[SalesForce] NamedCredentials update after sandbox refresh

I have some Custom Settings and Named credentials configured since I make call outs to external systems. But every time I refresh any of my sandbox, I have to manually update the Custom Settings and Named Credentials. I tried to create a Sandbox template but couldn't find a way to exclude Named Credentials and Custom Settings there. Also, thought of writing an APEX class which I can execute after refresh but I think Custom Settings can be updated via APEX but since Named Credentials is a read only object, I didn't find this option much suitable as well. Could someone advise what is the best practice to handle this situation?

Thanks in advance!

Best Answer

One of the approaches I can think of is to Use Salesforce metadata API wrapper like one maintained by Financial Force to implement logic to update named credentials .

You will need to put the logic inside class implementing SandboxPostCopy interface

global class UpdateNamedCredential implements SandboxPostCopy {
   global void runApexClass(SandboxContext context) {
      System.debug('Hello Tester Pester ' + context.organizationId()
       + ' ' + context.sandboxId() + context.sandboxName());
      // Insert logic here to update named credential

  }
 }
Related Topic