I have created managed package that uses metadata API to create connected App. It is working fine in my developer org where I am creating package. When I install this package in different org, It is asking for remote site setting.

I added a method to create remote site setting, which is working fine in my developer org.when I add this method in package and install in different org, again that requires endpoint.

How can I resolve this problem ?

  • 2
    To create remote site setting you need to add the endpoint of the org where you are creating the remote-site setting
    – Ashwani
    Commented Feb 7, 2017 at 7:14
  • 1
    I believe metadata API requires endpoint of salesforce instance, so it should be a post package installation step.
    – Raul
    Commented Feb 7, 2017 at 7:45
  • 1
    @Ashwani I am trying to create remote site setting from VF page and getting error "Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = my-domain-name--khel.ap2.visual.force.com/services/Soap/m/38.0" . Do I need to create this endpoint manually ? Commented Feb 7, 2017 at 7:52
  • 1
    @RahulSharma yes I am creating remote site setting and connected app through button on a VF page . After installing the package . Commented Feb 7, 2017 at 7:55
  • @AJAYPRAKASHDUBEY that endpoint must be added into the org before invoking the metadata api. Metadata API required callout.
    – Ashwani
    Commented Feb 8, 2017 at 3:06

1 Answer 1


You may have performed callout not to a canonical URL but to Visualforce domain or some other domain. You can actually perform successfully self-callouts without any RemoteSiteSettings, but you need to get the correct Domain URL by calling getBaseURL() method

 * Determines the true API hostname for a Salesforce org using the Identity API.
 * eg 'https://pod.salesforce.com' (most orgs)
 * eg 'https://custom.my.salesforce.com' (my domain)
 * eg 'https://custom--dev.sandbox.my.salesforce.com' (sandbox orgs)
public static String getBaseURL() {
    String orgId = UserInfo.getOrganizationId();
    String userId = UserInfo.getUserId();
    String sessionId = getLexSid();
    //use getSalesforceBaseUrl within batches and schedules (not Visualforce), and fix inconsistent protocol
    if (sessionId == null) {
        return Url.getSalesforceBaseUrl().toExternalForm().replace('http:', 'https:');
    PageReference pr = new PageReference('/id/' + orgId + '/' + userId);
    pr.getParameters().put('oauth_token', sessionId);
    pr.getParameters().put('format', 'json');
    //within test context use url class, else derive from identity api
    String data = Test.isRunningTest() ? '{"urls": {"rest": "' + Url.getSalesforceBaseUrl().toExternalForm() + '"}}' : pr.getContent().toString();
    Url rest = new Url(new Parser(data).readString('urls.rest').replace('{version}', '55'));
    return rest.getProtocol() + '://' + rest.getHost();

Once you know the correct domain (https://custom.my.salesforce.com or https://custom--dev.sandbox.my.salesforce.com), you may perform Metadata API calls to create Connected Apps or Remote Site Settings to different sites or Visualforce domain or Lightning domain.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .