As remote site setting is essential for making callouts to external systems.
We can create remote site through apex code:
We can create remote site through apex code:
Steps:
1.
Add a
metadataService class either through WSDL or you can use attached file: metadataService.class
2.
Use below code:
public void createRemoteSiteSetting(){
MetadataService.MetadataPort service = createService();
MetadataService.RemoteSiteSetting remoteSiteSettings = new MetadataService.RemoteSiteSetting();
remoteSiteSettings.fullName = ‘abc123';
remoteSiteSettings.url = 'http://www.clrdp727.com';
remoteSiteSettings.isActive=true;
remoteSiteSettings.disableProtocolSecurity=false;
service.createMetadata(new
List<MetadataService.Metadata> { remoteSiteSettings });
}
// This method returns the metadata service, using this we can fire action to create the remote site settings.
public static
MetadataService.MetadataPort createService()
{
MetadataService.MetadataPort service1 = new MetadataService.MetadataPort();
service1.SessionHeader = new MetadataService.SessionHeader_element();
service1.SessionHeader.sessionId = UserInfo.getSessionId();
return service1;
}
Hello,
ReplyDeleteI couldn't find the attached file to metadataService.class,
could you please attach it again,
thank you!
http://www.exceptionlesscode.com/how-to-create-remote-site-settings-through-apex/
DeleteHi Hanna,
DeletePlease find below the link
https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls
http://exceptionlesscode.azurewebsites.net/wp-content/uploads/2013/05/MetadataServiceOnlyCreateRemote.txt
ReplyDelete