+ Start a Discussion
babloo123babloo123 

Email Template Type VisualForce

Need to create a visual force email template on a custom Object to view fields (merge fields on that object) can some one guide how?

if any example some one has?
BalajiRanganathanBalajiRanganathan
https://developer.salesforce.com/page/VisualForceEmailTemplates_sample
babloo123babloo123
Hi Balaji,

            I am trying on custom object and I need two merge fields on it

1. Lookup of contact name on the Custom Object
2. Detailed Link of that record

when I try related to Lookup of contact name I am getting 18 digit id instead of name can you guide me how to get those both?
BalajiRanganathanBalajiRanganathan
for Lookup record contact name use {!<custom_object__c.contact__r.firstName>} {!<custom_object__c.contact__r.lastName>}

For Detailed Link of that record, you can use the following work around

<apex:variable var="url" value="{!LEFT($Api.Partner_Server_URL_140, FIND(".com/",$Api.Partner_Server_URL_140)+3)}"/>
 Link to &nbsp;<apex:outputLink value="{!url}/{!relatedTo.Id}">Record</apex:outputLink>

or  you can use
https://<your-instance>.salesforce.com/{!relatedTo.id}

 
babloo123babloo123
Hi Balaji,

                The Link one is working fine but the Contact is not working. The Contact name on our object is Reviewer_Name__c but it is not working and if I use related to and reviewer Name then it is giving 18 digit Id other than name can you please guide me there
BalajiRanganathanBalajiRanganathan
did you use the below to display contact name? replace <custom_object__c> with your object API Name
{!<custom_object__c>.Reviewer_Name__r.firstName}  {!<custom_object__c>.Reviewer_Name__r.lastName}  
babloo123babloo123

<messaging:emailTemplate subject="PCORI: Reviewer Unclear About COI Status" recipientType="Contact" relatedToType="COI_Expertise__c">
<messaging:htmlEmailBody >
 <html>
<body>
Reviewer Name: {!<COI_Expertise__c>.Reviewer_Name__r} 

https://cs30.salesforce.com/{!relatedTo.id}
 </body>
 </html>
 </messaging:htmlEmailBody>
</messaging:emailTemplate>

I am trying above code but now it says error below

Error: Syntax error. Found '<'

If I remove < then also not working throwing below error


Error: Unknown property 'core.email.template.EmailTemplateComponentController.COI_Expertise__c'
 

BalajiRanganathanBalajiRanganathan
Use the line below 
Reviewer Name: {!COI_Expertise__c.Reviewer_Name__r.firstName}  {!COI_Expertise__c.Reviewer_Name__r.lastName}
babloo123babloo123
Balaji getting the below error

Error: Unknown property 'core.email.template.EmailTemplateComponentController.COI_Expertise__c'
BalajiRanganathanBalajiRanganathan
Sorry overlooked into it. the below should work

Reviewer Name: {!relatedTo.Reviewer_Name__r.firstName}  {!relatedTo.Reviewer_Name__r.lastName}
 
babloo123babloo123
Also ID is not working nothing comes after my instance can you help rectify this plz
babloo123babloo123
No Balaji nothing is poping up actually I used HTML template it is working fine when I used testing but in actual scenario it is not poping up any names and link. Can you let me know any specific reason?
babloo123babloo123
Since HTML was not working I came to use VF page
BalajiRanganathanBalajiRanganathan

you mean the below line is not working?
https://cs30.salesforce.com/{!relatedTo.id}

there is no issue with the code above. preview the email template by selecting the contact and an COI_Expertise__c record. you should see the id populated.
babloo123babloo123
Balaji the values pop up when I test but in actual scenarion nothing is poping up can you let me know if any specific reason or something that I have to check( both HTML & VF Page)
BalajiRanganathanBalajiRanganathan
Actual Scenario for you  or for someone else?. if it works in test, then it is  not a problem with the email template. it could be related to security issue.check the user profile, if they have read access to object and read access in Field Level Security for that object.
babloo123babloo123
Actual Scenario for me It is read access to object and field as well but nothing pop ups when it actually has to fire but when I use test and verify merge fields it works