I have a custom setting present in production which consist of username and other related user details. Now, every time I create a new Sandbox I have to manually go and edit the custom setting in sandbox and edit the data that got populated via Production. Is there a way to populate the custom setting data on creation of new sandbox?

  • 1
    Is this a full, partial, or developer sandbox? – Eric Jan 24 '17 at 5:04
  • @Eric Full Sandbox – Gaurav Khandekar Jan 24 '17 at 5:12

Developer Sandbox

You will have to write a class which implements the SandboxPostCopy Interface.

global class HelloWorld implements SandboxPostCopy {
    global void runApexClass(SandboxContext context) {
        System.debug('Hello Tester Pester ' +
            context.organizationId() + ' ' + context.sandboxId() +

Replace the system.debug call with logic to create your custom setting records.

Partial Copy Sandbox

You can include the custom settings in a sandbox template.

Full Sandbox

All data carries over automatically, including custom settings.

  • @GauravKhandekar - While the answer is solid, how will it help if you said it was a full sandbox? Data should copy over automatically so either it is not a full sandbox or there is something going on – Eric Jan 24 '17 at 6:42
  • @Eric I'm trying to implement the logic of populating the username present in sandboxes into the custom setting. The logic for this would go in the above mentioned class itself. So, i do agree that the custom setting from production will have data in it, what i'll be trying to do is over write it with the new logic. I'm still working on the code and will update you accordingly. – Gaurav Khandekar Jan 24 '17 at 6:52

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.