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.
Note:
Create Custom Metadata Types Using Metadata API
Create Update Custom Label by 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
- 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