I can see and use encrypted field in user mode with View Encrypted Data permission. But in System mode it always as "stars" (***********). Is it possible to see it in the System mode as plain text?
3 Answers
The "view encrypted data" permission is required for the user to see the field value in plain text!
Note you cannot edit this on standard profiles and will require you to clone the standard administrator profile.
An elegant solution is to create a permission set and have the “view encrypted data” permission enabled! Assign the permission set to the users needing it!
A note here is you need to log out and log back in to see this change!
The above is all true if you have classic encryption enabled!
If you have shield enabled then you don’t need this permission and one can view this field in plain text as the data is encrypted at rest!
Read more on shield encryption behavior for masked fields below article
-
How about in Apex Test classes, I tried assigning "view encrypted data" perm but it still couldn't work? I need it for code test coverage– compskiCommented Jan 2 at 6:58
Only the users with the permission "View Encrypted Data" enabled on the profile assigned to the user can see the encrypted data.
I found some workaround for it. I can create Visualforce page and put encrypted field to parameters and then it possible to immediately get this parameter as plain String even in System mode:
PageReference ref = new PageReference('/apex/mypage');
ref.getParameters().put('param', record.Encrypted_Field__c);
String decryptedFieldValue = ref.getParameters().get('param');
//or if you want to get value for example in getter method
String decryptedFieldValue = ApexPages.currentPage().getParameters().get('param');