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.