3

I have a custom DOB field which is platform encrypted. I can see the field value as '7/7/1777' in standard layouts and in highlights panel in console. But when the field is used in a VF page it displays the original valeu eg:- '6/6/2016'.

My requirement is that, users can only see the original value when they have the 'View encrypted data' permission enabled.

How do I achieve the above in Visualforce Pages?

On page load the value is retrieved from the contact and shown to the agent. But it should show as '7/7/1777' instead of the original value.

  • 1
    It would be helpful to see how you are passing the value to the VF page, is it an inputfield bound to the field or variable you have created in the controller? – Girbot Mar 25 '17 at 19:36
  • Are you using a Standard Controller or a Custom Controller? – Carlos Naranjo Mar 25 '17 at 19:45
  • <apex:inputText id="dob" tabindex="7" value="{!conbirthdate}" style="width: 139px;"/> On page load the value is retrieved from the contact and shown to the agent. But it should show as '7/7/1777' instead of the original value. – user43081 Mar 25 '17 at 20:00
  • looks like you are bypassing the standard platform design, why are aren't using inputfield and binding to the field? – Girbot Mar 25 '17 at 22:37
1

To my explain my comment further take code examples below:

VF page:

<apex:page standardController="Contact" extensions="dob_ext">
    <apex:form>
        <apex:inputField value="{!theContact.testDOB__c}" />
        <apex:inputText value="{!dob}"/>    
    </apex:form>
</apex:page>

Extension:

public class dob_ext {
    public String dob {get;set;}
    public Contact theContact {get;set;}

    public dob_ext(ApexPages.StandardController ctr){
        theContact=(Contact)ctr.getRecord();
        theContact=[select Id, testDOB__c from Contact where Id=:theContact.Id];
        dob = theContact.testDOB__c;

    }
}

The output is:

enter image description here

Using <apex:inputfield> will maintain the field level security/encryption for the field it is bound to, <apex:inputtext> will not. Apex has access to the unmasked/un-encrypted value so you passing it to your own variable it will assign the actual value, as the above demonstrates.

As part of my developer certification preparation I found some documentation explaining this, which I will add if I can find it.

Note: The above was done using classic encryption as I do not have access to an org with shield active.

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.