You need to sign in to do that
Don't have an account?
Shivani Thapar
Custom Controller on Visual Force
Hi there, id like to create a custom controller on a visual force email template similar to this
http://www.salesforce.com/docs/developer/pages/Content/pages_email_templates_with_apex.htm
but listing unpaid invoices? anyone know how?
Thanks for the help
http://www.salesforce.com/docs/developer/pages/Content/pages_email_templates_with_apex.htm
but listing unpaid invoices? anyone know how?
Thanks for the help
1. Your controller should be like this.
Here is the sample code :
public class FindunpaidInvoices {
private final List<invoice__c> invoices;
public FindunpaidInvoices() {
invoices = [select amount__c, Toname__c from invoice__c where Status__c = 'Unpaid'];
}
public List<invoice__c> getUnpaidInvoices() {
return invoices;
}
}
=====================================================
2.You will use above controller in Your Visualforce Component like this.
Here is the sample code,
Suppose your Visualforce Component name is "AllUnpaidInvoices"
<apex:component controller="FindunpaidInvoices " access="global">
<apex:dataTable value="{!UnpaidInvoices}" var="invoice">
<apex:column>
<apex:facet name="header">Amount Name</apex:facet>
{!invoice.amount__c}
</apex:column>
<apex:column>
<apex:facet name="header">To Name</apex:facet>
{!invoice.Toname__c}
</apex:column>
</apex:dataTable>
</apex:component>
==============================================================
3. Now you will use above Visualforce Component like this.
Here is the Sample code.
<messaging:emailTemplate subject="Embedding Apex Code" recipientType="Contact" relatedToType="Opportunity">
<messaging:htmlEmailBody>
<p>As you requested, here's a list of all Unpaid Invoices</p>
<c:AllUnpaidInvoices/>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Please let me know my solution works for you.
Thanks & Regards,
Sameer Tyagi.
http://mirketa.com
I am getting this error at the moment... any idea what Im doing wrong?
Also is there a way I can also show my unpaid invoices as aging, from 0-30 days, 31 to 60, 61 to 90, 91 to 120, and 121 and older?
You have merged Component and Email templete Code in same place.
You have to code at three places.
1. Controller : go to classes from left pane and create new class
2. Component : go to component from left pane and create Component
3 Email templete : go to Email templete : select Visualforce Templete and Create VF templete
NOTE : the API field name I am using in Controller are just for Sample
Please enter the fields name according to your Organisation API
For Example Invoice__c , Amount__c , Toname__c ,
Regards,
Sameer
Only Developer Edition, Sandbox, and Trial organizations have the ability to create, edit, and delete Apex classes and triggers directly in the Salesforce CRM user interface. Unlimited Edition and Enterprise Edition production organizations can execute Apex and can view Apex in the user interface, but modifying Apex in the user interface is not allowed.
There is no tutorial video for this requirment, However salesforce has provided PDF's books to learn Salesforce, apex guide, Visualforce guide etc.
http://www.salesforce.com/us/developer/docs/apex_workbook/apex_workbook.pdf
http://www.salesforce.com/us/developer/docs/workbook_vf/workbook_vf.pdf
But It will be a long process for you to learn everything in detail for just small requirment.
Now come to your requirment.
1. If you are working on Unlmited or Enterprise edition Production Environment then first you need to create sandbox for your org.
here is the steps to create sandbox
From Setup, click Sandboxes or Data Management. | ...
Click New Sandbox.
Enter a name and description for the sandbox. ...
Select the type of sandbox environment you want. ...
Select the data you want to include in your sandbox (you have this option for a Partial Copy or Full sandbox). ...
Click Create.
2. Now login In Sandbox and you will create controller, Click Setup from top right --> then type Apex Classes in left search bar ---> click on Apex Classes
Click new button and Create your class.
3. Now you have to deploy your apex class from Sandbox to production.
4. After that you can create your Visualforce Componenet and Visualforce Templete directly on production.
Thanks & Regards,
Sameer Tyagi
http://mirketa.com
I got to two
3) i need to deploy it to production - how do I do this? do I need to do testing or no? and also I do not have the ability to deploy change sets on my enterprise sandbox... is that ok?
4) can you please explain a little further on how to do this step?
Thanks
Great!
For Step 3
Yes, you also need to create test class for your controller.
please review this link for test class
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods.
You have to deploy your controller with test class.
You can deploy via change set OR eclipse( a Software)
Change set available in Sandbox and production both.
You will outbound change set in Sandbox
and Inbound change set in Production
For Step 4
To Create component
Click Setup from top right --> then type Component in left search bar ---> click on Component
Click new button and Create your Component .
To Create Visualforce Templete
Click Setup from top right --> then type Email Templete in left search bar ---> click on Email templete
Select Visualforce Templete and create your templete.
Sameer Tyagi