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
SabinaSabina 

Translated picklist value in Visualforce email template, the plain text part

Hello,

I have a picklist and its values have been translated to different languages. I set up a Visualforce email template with custom labels and field values to sent to contacts based on their language, using 
<messaging:emailTemplate subject="{!$Label.Email_Title}" recipientType="Contact" language="{!recipient.Language__c}">
All the custom labels are translated fine. The picklist value in the <messaging:htmlEmailBody> part of the email also displays in the correct language, using this:
<apex:outputField value="{!recipient.Industry__c}"/>

However, if I try to use apex:outputField in the <messaging:plainTextEmailBody> part of the email, it won't save because of this error:
Save error: <messaging:plainTextEmailBody> cannot contain <apex:outputField>. 
Using apex:outputText doesn't translate the value. 
Does anyone know how to get the translated value of a picklist in the plain text part of the email?

Thanks

 
Best Answer chosen by Sabina
SabinaSabina
I managed to solve this by using a component + controller.

To display the field:
<c:contactIndustry cId="{!recipient.Id}" />

The contactIndustry component:
<apex:component controller="contactIndustryCtrl" access="global">
	<apex:attribute name="cId" assignTo="{!contactId}" type="Id" description="Contact ID" />
	{!industry}
</apex:component>

The controller:
public class contactIndustryCtrl {
    public Id contactId {get;set;}
    public String getIndustry() {
    	return [select toLabel(Industry__c) from Contact where Id =: contactId].Industry__c;
    }
}