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 

Apex code that will show an encrypted field

Hi 

I have a encrypted custom field. I want this field to be shown as plain text in an e mal template. I am using the apex outputField  <messaging:attachment >
Encrypted Account Number: <apex:outputField value="{!relatedTo.ts2__Employee__r.Sample_Bank_Acc__c}"/>
</messaging:attachment>
However the field remaims encypted in the e mail attachment. 
Does anyone know a way around this??
Satish_SFDCSatish_SFDC
The text remains encrypted unless the user has the View Encrypted Data permission.

Regards,
Satish Kumar
Aidan KeenanAidan Keenan
Hi Satish

I have the view encrypted data permission turned on. I can view the encrypted field but in the e mail template, the field remains encrypted.
blucasblucas
There's a note in the Implementation Notes section of the About Encryped Custom Fields (https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_about_encrypted_fields.htm&language=en) help topic -
"You can use encrypted fields in email templates but the value is always masked regardless of whether you have the “View Encrypted Data” permission."

The only way I found around this was to have a template that used a custom visualfource page.Then in the APEX custom controller for the page you can do a HttpRequest back to the SalesForce REST service to pull whatever record your looking for. Now while this worked, it felt extremely "hacky" and ultimately I decided against using it.