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
mw6mw6 

Copy an encrypted text field data into another text field

I have an encrypted field NRIC_NEW__C, after saving the record, I would like to copy the content of this field into another text field, how can I do this
Best Answer chosen by mw6
Sudipta DebSudipta Deb
Hi,

Please read the below url for Encrypted fields.
https://developer.salesforce.com/docs/atlas.en-us.securityImplGuide.meta/securityImplGuide/fields_about_encrypted_fields.htm

Existing custom fields cannot be converted into encrypted fields nor can encrypted fields be converted into another data type. 
The value of an encrypted field is only visible to users that have the “View Encrypted Data” permission."
So, even if you query the encrypted text from a user not having above permission, you will get it in encrypted form(****) instead of actual value.

Better approach is to store it in custom field or text field, and use Crypto class (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_crypto.htm) for custom encryption and decryption.

Please select this as "Best Answer" if it helps. Thanks.