You need to sign in to do that
Don't have an account?
Sanjana Rajasekar
Reference History in Visualforce Email Template
I have Custom Object "Work_Order__c" . I want to send a email when the value field in this Object changed. How can I use
Work_Order__c__History in the template.
And If the old value and updated value is not same , I need to highlight in red color.
<messaging:emailTemplate recipientType="Contact" relatedToType="Work_Order__c">
<messaging:HtmlEmailBody >
<apex:outputPanel rendered="{!relatedTo.Job_Name_Text__c!= NULL}">
<apex:outputLabel value="Job Name: " />
<font color="{!IF((relatedTo.Work_Order__c__History[0].OldValue.Job_Name_Text__c != relatedTo.Work_Order__c__History[0].NewValue.Job_Name_Text__c), 'red', 'black')}">
<apex:outputText value="{!relatedTo.Job_Name_Text__c}" />
</font>
</apex:outputPanel>
</messaging:HtmlEmailBody>
</messaging:emailTemplate>
Work_Order__c__History in the template.
And If the old value and updated value is not same , I need to highlight in red color.
<messaging:emailTemplate recipientType="Contact" relatedToType="Work_Order__c">
<messaging:HtmlEmailBody >
<apex:outputPanel rendered="{!relatedTo.Job_Name_Text__c!= NULL}">
<apex:outputLabel value="Job Name: " />
<font color="{!IF((relatedTo.Work_Order__c__History[0].OldValue.Job_Name_Text__c != relatedTo.Work_Order__c__History[0].NewValue.Job_Name_Text__c), 'red', 'black')}">
<apex:outputText value="{!relatedTo.Job_Name_Text__c}" />
</font>
</apex:outputPanel>
</messaging:HtmlEmailBody>
</messaging:emailTemplate>
Relationship name should be 'Histories', can you check below query. Something like below.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_hist.htm
Please mark as Best Answer if above information was helpful.
Thanks,