• Vikas Sharma 41
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I am having a problem accessing the content of an encrypted field from an Apex class. According to the Encrypted Field documentation -- "When an encrypted custom field is manipulated in Apex Code, the value is always unmasked,regardless of the permissions of the user. " However, in my Apex code the field value is always masked.

 

I confirmed this by parsing the actual field value character by character, since encrypted fields are always masked in system.debug() statements.

 

Participant__c partic = [SELECT ID, Social_Security_Number__c FROM Participant__c WHERE ID = :this.recordID LIMIT 1];
if (partic.Social_Security_Number__c != null) {
	string ssn = '';
	for (integer n = 0; n < partic.Social_Security_Number__c.length(); n++) {
		string x = partic.Social_Security_Number__c.subString(n,n+1);
                if (x == '*') x= 'x';
                ssn += x;
    	}
}

 In the above code I found that the characters in the encrypted field were actually an asterik (*). I confirmed this by checking for the "*" and replacing it with a "+".  (I could have done this with a Replace(), but I wanted to actually copmare each character one at a time to be sure).

 

Shouldn't I be able to retrieve the full umasked value of the encrypted field in my Apex code?

 

Best Regards,

 

Mike