Thursday, August 9, 2018

Remote Site Settings : Way to Create/Update Using Apex (Metadata API)

We can create or update Remote Site Settings in Apex using Metadata API.

You can either download Metadata API WSDL from Salesforce and generate apex class by clicking on Generate from WSDL button.

Or you can download the MetadataService class from below link:


Below is sample to code to create remote site settings.

Execute this static method from execute anonymous and check if records created or not.


Below is snapshot of remote site settings created

  • I have used upsertMetadata method. If you want to only insert new remote site setting, then use insertMetadata method
  • fullname property is considered in order to decide whether remote site setting needs to be created or updated.
Hope this will help!!!

Create Custom Metadata Types Using Metadata API
Create Update Custom Label by Using Metadata API


  1. Hi, I'm getting this error:

    Error: Method does not exist or incorrect signature: void createService() from the type MetadataAPIUtility line 24 column 52

  2. Hello ,
    thanks for this tutorial (very useful)
    I encounter an error when trying to execute the code in anonymous MetadataAPIUtility.createRemoteSiteSettings();

    Line: 13497, Column: 1
    System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

    I don't know why because i'm trying to udpate any record other than the remote site settings. Any idea ?

    1. NO problem: I found my error... => there was something i was trying to update before creating the remotesite Settings

  3. Hi,
    How can i fetch remote site setting records using apex?

    1. Hi Raj,

      You can use tooling API to fetch remote site settings. Execute below code in developer console which uses tooling API to get remote site settings details:

      HttpRequest req = new HttpRequest();
      req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
      req.setHeader('Content-Type', 'application/json');
      String domainUrl=URL.getSalesforceBaseUrl().toExternalForm();

      Http h = new Http();
      HttpResponse res = h.send(req);

      Now parse the JSON response.

  4. Hi,
    I'm Trying to create remote site Setting in apex using Metadata Service.But i'm Unable to create, It says it 'Unauthorized endpoint'.The remote site is my Base URL,any Idea to resolve this
    Thanks in advance.

    1. Hi Ankit,
      I am getting same issue. Are you able to resolve this issue?

  5. The time has arrived now IT staff can easily perform a unified desktop management for remote workers, remote offices, and local networked users  task list templates

  6. Hi,
    Can we use this as a part of managed package, to update subscriber org

  7. This comment has been removed by the author.

  8. Did you figure out how to query for the list of existing RemoteSiteSettings at all?

  9. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. web-agency

  10. Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. sviluppo sito ecommerce

  11. This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff. sites like fiverr australia

  12. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. WordPress Developer Brisbane

  13. I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
    quenza software

  14. I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.

  15. I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.

  16. I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me.