function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ido Greenbaum 10Ido Greenbaum 10 

Custom Field Formula - Image, encapsulated in a VisualForce Email Template

I have set a Custom Field ('Priority_Flags__c') on the Case object, to represent priority flags as follows:
 
IMAGE( 
CASE( Priority, 
"Low", "/img/samples/flag_green.gif", 
"Medium", "/img/samples/flag_yellow.gif", 
"High", "/img/samples/flag_red.gif", 
"Critical", "/img/samples/flag_red.gif", 
"/s.gif"), 
"Priority Flag")
I included this custom field to be merged in a VisualForce Email Template as follows:
<messaging:emailTemplate subject="[Assignment] Case #{!relatedTo.CaseNumber}: {!relatedTo.Subject}" recipientType="User" relatedToType="Case">
    <messaging:htmlEmailBody >
    <html>
    <style type="text/css">
            body {font-family: arial; size: 12pt;}
        </style>
    <body>
        The following case was assigned to <b>{!relatedTo.Owner.Name}</b>:
        <br />------------------------
        <br />• Case #: {!relatedTo.CaseNumber}
        <br />• Account: <apex:outputLink value="https://my.salesforce.com/{!relatedTo.Account}"> {!relatedTo.Account.Name}</apex:outputLink>
        <br />• Contact Name: {!relatedTo.Contact.Name}
        <br />• Case status: {!relatedTo.Status}
        <br />• Priority: {!relatedTo.Priority_Flags__c} {!relatedTo.Priority}
        <br />• Link: https://my.salesforce.com/{!relatedTo.Id} 
        <br />------------------------
        <br />        
</body>
</html>
</messaging:htmlEmailBody>   
</messaging:emailTemplate>
It seems that the rendered Merged Field is not the image as expected, but the img HTML statement:

User-added image

Is there a way to make this work, and render the IMAGE in the VisualForce Email Template? 
Best Answer chosen by Ido Greenbaum 10
Dagny FernandesDagny Fernandes
Create another formula text field, use if else condition and display only the image url in that filed "/img/samples/flag_green.gif" 
Eg Field Name: "Priority_Flags_Url__c"
 
And use this apex tag in your Visualforce email template:
<apex:image id="theImage" value="{!relatedTo.Priority_Flags_Url__c}" width="20" height="20"/>

All Answers

Dagny FernandesDagny Fernandes
Create another formula text field, use if else condition and display only the image url in that filed "/img/samples/flag_green.gif" 
Eg Field Name: "Priority_Flags_Url__c"
 
And use this apex tag in your Visualforce email template:
<apex:image id="theImage" value="{!relatedTo.Priority_Flags_Url__c}" width="20" height="20"/>
This was selected as the best answer
Ido Greenbaum 10Ido Greenbaum 10
Perfect, thank you.