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:

MetadataService.cls

Below is sample to code to create remote site settings.


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

 MetadataAPIUtility.createRemoteSiteSettings();

Below is snapshot of remote site settings created


Note:
  • 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


4 comments:

  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

    ReplyDelete
  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 ?

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

      Delete