Salesforce Asked by AshBringer on December 26, 2021
I have a Classic Email Template of Visualforce type. I’m trying to put some dynamics value on the subject attribute base on picklist values, however I’m getting the API Name rather than the label value of the record.
<messaging:emailTemplate
replyTo="[email protected]"
subject="{!RelatedTo.PickMe__c}" -> this returns the API name , I want the label
recipientType="User" relatedToType="Case">
So far , I hoped I could solve it with a CASE function on every API Name, however I have hit the formula length (39xx chars).
Is there some kind of getLabel() function I can apply ? I didn’t find one though..
Any idea on how can I solve it ?
To get the label for a picklist value, you can use Apex:
public String getPLVLabel(SObjectField fld, String val)
Schema.DescribeFieldResult dfr = fld.getDescribe();
List<Schema.PicklistEntry> plvs = dfr.getPicklistValues();
for (PicklistEntry ple: plvs) {
if (plv.getValue() == val) {return plv.getLabel();}
}
return null;
}
Because you are trying to get the label in the VF email template's subject, using a custom component and controller is not going to help because subject is an attribute of messaging:emailTemplate
and it can only be:
So, you're going to need a shadow field on Case called PickMe_AsLabel__c
that you populate in the before update/before insert Case trigger using the above ccode, invoked like this:
for (Case cs : Trigger.new) {
cs.PickMe_AsLabel__c = new MyUtil.getPlvLabel(Case.PickMe__c,cs.PickMe__c);
}
Answered by cropredy on December 26, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP