Refreshing sandboxes can be a pain in any Salesforce admin's side. This can involve waiting for sandbox refreshes, resetting all required users' emails, and creating test data or obfuscating production data. If you're looking to speed up this process, you can use Apex classes to perform repetitive tasks like above after refreshing sandboxes.
Below, we'll discuss the SandboxPostCopy Interface and how to use it to modify data after refreshing your sandbox.
What is the SandboxPostCopy Interface?
SandboxPostCopy is an interface you can implement in an Apex class. You can use this to run Apex code after refreshing a sandbox.
How to Run Apex Code During Refreshes
To run an apex class for a sandbox refresh, you need to input the apex class name during the sandbox refresh screen. You can see the menu to input below:
Example Use Cases
Most Salesforce Admins end up using this for one of these 3 reasons:
- Removing .invalid from email addresses. This allows faster, automated refreshing of emails for specific users.
- Generating test data. If your organization constantly uses developer sandboxes, generating sample data en masse can simplify usage.
- Censoring sensitive information. If your organization uses partial or full sandboxes, censoring emails, phone numbers, and names can be very beneficial. Additionally, changing this data can prevent running automation on your real customer data, resulting in unexpected emails or texts from your sandbox.
Example: Removing .Invalid from Emails
Below is an example implementation of the SandboxPostCopy interface. You can see the two apex classes below. It's important to note that this implementation uses a custom field, Refresh
which is a checkbox on the User object. This allows you to select which users are eligible to have their email changed.
Conclusion
Refreshing sandboxes can be automated and made easier through the SandboxPostCopy interface. This allows for easier sandbox refreshes, and better data for testing.
Want to see this content in video form? Check out the video here:
If you are interested in how G2 Technologies can support your Salesforce needs, get in touch: https://g2technologies.com/pages/contact