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
Hi, I'm getting this error:
ReplyDeleteError: Method does not exist or incorrect signature: void createService() from the type MetadataAPIUtility line 24 column 52
Hi,
DeleteI have updated code.
Hello ,
ReplyDeletethanks 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 ?
NO problem: I found my error... => there was something i was trying to update before creating the remotesite Settings
DeleteHi,
ReplyDeleteHow can i fetch remote site setting records using apex?
Hi Raj,
DeleteYou 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();
system.debug('********domainUrl:'+domainUrl);
req.setEndpoint(domainUrl+'/services/data/v44.0/tooling/query/?q=Select+EndpointUrl,SiteName+from+RemoteProxy');
req.setMethod('GET');
Http h = new Http();
HttpResponse res = h.send(req);
system.debug(res.getBody());
Now parse the JSON response.
Hi,
ReplyDeleteI'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.
Hi Ankit,
DeleteI am getting same issue. Are you able to resolve this issue?
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
ReplyDeleteHi,
ReplyDeleteCan we use this as a part of managed package, to update subscriber org
very interesting keep posting. https://europa-road.eu/hu/gepszallitas-miskolc.php
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteDid you figure out how to query for the list of existing RemoteSiteSettings at all?
ReplyDeleteThanks 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
ReplyDeleteThanks 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
ReplyDeleteThis 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
ReplyDelete