on the best practice section of this documentation:


it says: You can still validate the values of encrypted fields using validation rules or Apex. Both work regardless of whether the user has the “View Encrypted Data” permission.

But if I dont have the permission and I try to do something like

Contact con = [SELECT Id, My_Encrypted__c FROM Contact WHERE Id = '0030I00001WoR9E'];
if (con.My_Encrypted__c == '456798') {
} else {

The debug log will show me noooo. So my question is how can I validate the field, or I am misunderstanding that sentence?


You can validate values in an Apex trigger by checking the values in Trigger.new or Trigger.old, and you can validate values in Validation Rules. If you query records without having the "View Encrypted Data" permission, the values will still be masked.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.