• Daksh Bansal
  • 0 Points
  • Member since 2017

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 1
Need urgent help, we have a requirement where we need to update remote site setting using apex. I have tried to search solution if this can possiable via tooling/metadata api but no luck. If anyone worked same kind of requirement please help.

My first question, Is it possible to add a remote site dynamically through apex ?


Regardless of the answer, I still tried to achieve this by using Metadata API within Salesforce. Below is my code.


public static void createremoteSiteSettings()
MetadataService.MetadataPort service = createService();
MetadataService.RemoteSiteSetting remoteSiteSettings = new MetadataService.RemoteSiteSetting();
//remoteSiteSettings.fullName = 'Test';
remoteSiteSettings.url = 'http://www.google.com';
MetadataService.AsyncResult[] results = service.create(new List<MetadataService.Metadata> { remoteSiteSettings });

public static MetadataService.MetadataPort createService()
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
return service;


I am getting this error : System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Must specify a {http://www.w3.org/2001/XMLSchema-instance}type attribute value for the {http://soap.sforce.com/2006/04/metadata}metadata element faultcode=soapenv:Client faultactor=


Any help would be appreciated !