1

on the best practice section of this documentation:

https://developer.salesforce.com/docs/atlas.en-us.securityImplGuide.meta/securityImplGuide/fields_about_encrypted_fields.htm

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') {
    System.debug('yess');
} else {
    System.debug('noooo');    
}

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

1

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.

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.