2

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!

  • See Mohith's answer - you use the Apex wrapper on the Metadata API (available in GitHub) and update the NamedCredential metadata resource. You don't use normal Apex DML, metadata API is done via callout – cropredy Dec 17 '17 at 6:11
2

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

  }
 }
  • Mohit - thanks for the details. I tried this approach as well but the challenge I am facing is how to update Named Credentials using APEX. You can reference Named Credentials in callouts but I am not aware of any apex code which can query and update the Named Credentials. – Suresh Dalal Dec 17 '17 at 1:56
  • You will need to import financial force wrapper for metadata api and that would allow you to edit the named credential . – Mohith Shrivastava Dec 17 '17 at 9:38

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.