I want to mask the account name of the account object, so that the user cannot view the account name. How can I do this? Please provide me some suggestions.

I want this type of patternenter image description here

  • 1
    Given that the account name is a mandatory field and is displayed by default on lookups this would be hard to do. What is the reason behind this as data visibility can be dealt with using Sharing and Roles?
    – Dave Humm
    Oct 22, 2018 at 10:48
  • 1
    If this relates to making data in a sandbox different from Production, e.g. in a Full sandbox this can best be achieved with either a script run from the Developer Console or extracting the data scrambling any sensitive fields and reloading with Data Loader.
    – Dave Humm
    Oct 22, 2018 at 10:53
  • There's also at least one appexchange product that can scramble the data for you. It's convenient because it can also copy production data to a sandbox while scrambling so developers have data to work with without having real production data.
    – sfdcfox
    Oct 22, 2018 at 13:21
  • 1
    Does this answer your question? Masking Sensitive Data in Sandboxes
    – Foo Bar
    Oct 13, 2023 at 17:37

1 Answer 1


You can use SandboxPostCopy interface that allows you run an Apex class as soon as sandbox is refreshed. Use that class to run a batch class that makes your data encrypted.

I have implemented similar for my project you can refer that

public class SanboxRefreshAnononimyser implements Database.Batchable<sObject>,SandboxPostCopy {

  public void runApexClass(SandboxContext context) {

      Database.executeBatch(new SanboxRefreshAnononimyser());


    public Database.QueryLocator start(Database.BatchableContext BC){ 
           String query='Select id,Name,PersonMobilePhone,PersonMobilePhone from Account';
          return Database.getQueryLocator(query);

    public void execute(Database.BatchableContext BC, List<Account> scope){

        for(Account acc:scope){




            acc.Name = SanboxRefreshAnononimyser.encryptText(acc.Name);

        update scope;  


    public void finish(Database.BatchableContext BC){


    private static String encryptText(String inputText){
        String clearText = 'the quick brown fox jumps over the lazy dog';

        Blob key = Blob.valueOf('123456789012345678901234');
        Blob cipherText = Crypto.encryptWithManagedIV('AES192', key, Blob.valueOf(inputText));
        String encodedCipherText = EncodingUtil.base64Encode(cipherText); 
        return encodedCipherText

Src: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_System_SandboxPostCopy.htm

That being said, if you have already refresh the sandbox, you can directly run this batch class in Apex to get it through.

 Database.executeBatch(new SanboxRefreshAnononimyser());

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .