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
Aidan KeenanAidan Keenan 

I want to use an encrypted custom field in an e mail template?

I want to use an encrypted custom field in an e mail template. I want the field to be visible to the recipient of this e mail. Here is the code that gets the custom field from the record in the visualforce e mail template      Encrypted Account Number: {!relatedTo.ts2__Employee__r.Sample_Bank_Acc__c}  Is there a way of doing this?
Sonam_SFDCSonam_SFDC
Hi Shane,

You can use encrypted fields in email templates but the value is always masked, regardless of whether you or the recipient have the “View Encrypted Data” permission.

The only means of displaying the encrypted value would be by using the <apex:outputField> component in a Visualforce email template, as this is the only component that supports presenting encrypted fields in Visualforce pag(email template).
Aidan KeenanAidan Keenan
Thanks for the reply. I am trying to use the <apex:outputField> in the e mail template but I am getting an error saying that this can not be used in an e mail template. Is there a workaround for this. Error: <messaging:plainTextEmailBody> cannot contain <apex:outputField>.
Sonam_SFDCSonam_SFDC
I did some tests as you mentioned the error and am getting the same in Visualforce template but not inside the regular VF page with outputfield tag - I ran through some previous cases and see the following workaround whiich you might want to check:
- make the field public but encrypt it before saving it in the record, and decrypt before adding it to the template. This however will require keeping the field synced at all time and adding a custom component to the email template.
The above workaround would require you to code more...

Aidan KeenanAidan Keenan
I used
 <messaging:attachment >
Encrypted Account Number: <apex:outputField value="{!relatedTo.ts2__Employee__r.Sample_Bank_Acc__c}"/>
</messaging:attachment>

This allowed me to use the apex outputField in the e mail tempplate, however the bank account number remains encypted when I open the attachment.