Home Salesforce How to Remove Customer Details After Refreshing Salesforce Org

How to Remove Customer Details After Refreshing Salesforce Org

by Dhanik Lal Sahni

Salesforce supports four types of Sandboxes. These sandboxes should be refreshed periodically to get updated metadata from the production org. Customer data is copied to the org when a full-copy sandbox is refreshed. We should remove customer demographic data from the Sandbox org. This post will explain how to remove customer details after creating or refreshing Salesforce org from production.

Why should we remove customer data?

When we have customer data in UAT or full copy sandbox org, the testing team might send a test email or a text to customers’ mobile phones. Customers can complain about this, and there might be a legal issue with sharing their details. Sometimes, the testing team can send an email with new policies that even the business has not published for the market. This can lead to big financial issues for the company.

Steps to Remove Customer Data from Sandbox

  1. Identify Objects for Customer Data
  2. Create Apex Job for Running After Sandbox Refresh
  3. Create a Sandbox for testing

1. Identify Objects for Customer Data

First, we must identify customer data that needs to be removed or changed. Once we identify customer data, we find out which objects and fields store it in Salesforce objects. We then prepare a list with each object and its field for data removal or changes.

2. Create Apex Job for Running After Sandbox Refresh

Salesforce’s SandboxPostCopy interface is designed to automatically execute custom logic after a sandbox is created or refreshed. This interface is invoked only once after the sandbox is fully refreshed or created.

We can use this SandboxPostCopy interface to

  1. Create or modify user detail
  2. Assign Profile/Permission set to user
  3. Resetting data for testing
  4. Activating integration for specific use cases

We will use this interface to replace/remove customer data. As we have a list of fields and objects where data needs to be changed, we will create a batch apex to update these data. A standard apex can throw a limit exception, as data in production can be high. We can also use Bulikified flow for this. For this post, I used a batch apex to update the information. In this batch apex, we will update the email and phone fields of the Account and Contact objects.

Create a test class for the above batch apex. They are required to be deployed in productions.

As these classes will be used in production while setting up sandbox refresh, we will deploy the above apex classes to production org.

3. Create a Sandbox for testing

Once we deploy changes to production, we can test them by creating a sandbox org. Let us create a UAT1 sandbox from production.

Salesforce Org Refresh- Create Sandbox

After this, put the Apex class name that will be called after Sandbox is refreshed or created.

Refreshing Salesforce Org - Put Apex Class

Once Sandbox is refreshed, you can check account and contact data or whatever customer data you want to replace.

Refreshing Salesforce Org - Clean Data in Salesforce

Summary

SandboxPostCopy interface lets developers and administrators automate specific actions immediately following the copy process, ensuring the sandbox is configured correctly. This feature simplifies post-sandbox-creation tasks and provides a consistent environment setup across different sandbox environments.

References

Related Posts

Need Help?

If you need help implementing this feature, connect with me on my LinkedIn profile, Dhanik Lal Sahni.

You may also like

Leave a Comment