I am trying to implement named credential in my integration I am getting error below:

The callout couldn't access the endpoint. You might not have the required permissions, or the named credential "IntegLead" might not exist.

Can Anyone help me to resolve this?

Label   IntegLead
Name    IntegLead
URL https://xxx.salesforce.com/  
Identity Type   Named Principal
Authentication Protocol Password Authentication
Username    xxxxx
password        xxxxx
Generate Authorization Header-enabled
Allow Merge Fields in HTTP Header   
Allow Merge Fields in HTTP Body 


public class SendLeadUsingRESTAPI {
   public class deserializeResponse
      public String id;
      public String access_token;
 public String ReturnAccessToken (SendLeadUsingRESTAPI leada)
      Http h = new Http();
      HttpRequest req = new HttpRequest();
      HttpResponse res = h.send(req);
      deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
      return resp1.access_token;
   public static void callcreateAcc (List<Id> ids)
     List<Lead> leads = [select lastname, company, status from lead where id in :ids];
     for (Lead ld :leads)
      ld.id = null;
      String jsonstr = (String)JSON.serialize(leads);
      SendLeadUsingRESTAPI leadb = new SendLeadUsingRESTAPI();
      String accessToken;
      accessToken = leadb.ReturnAccessToken(leadb);      
      if(accessToken != null){
      String endPoint = 'https://xxx.salesforce.com/services/apexrest/Lead/doPost';
      Http h2 = new Http();
      HttpRequest req1 = new HttpRequest();
      req1.setHeader('Authorization','Bearer ' + accessToken);
      HttpResponse res1 = h2.send(req1);

Is this part of a managed package.

If so you will need to prefix the named credential with __ (two underscores) to indicate that you are using a named credential from the local namespace. Source. You will need to skip this prefix in the packaging Dev org.

Another source suggests that you need to include the package namespace after Winter '16.

Before winter '16 you can use the Named Credential without the package name. From winter '16 you need to include the package name in the named credential.

BEFORE Winter '16 : 'callout:namedCredential'
AFTER Winter '16 : 'callout:packageName__namedCredential'

It is also worth checking that the Remote Site Settings will allow access to the URL from the named credential.

  • 1
    No its not part of managed package.I have used underscore.But I am getting error-The callout couldn't access the endpoint. You might not have the required permissions, or the named credential "__IntegLead" might not exist. – Vidhyasagaran Muralidharan Sep 6 '16 at 20:19
  • @VidhyasagaranMuralidharan Have you added the Remote Site Setting for the target URL as well? – Daniel Ballinger Sep 7 '16 at 1:14
  • 2
    There was problem in the remotesite setting.got it thanks – Vidhyasagaran Muralidharan Sep 7 '16 at 3:06
  • @DanielBallinger please could you help with this – Robs Apr 26 '19 at 22:46

I Had same issue, from my understanding we dont have to add the remote site if we are using named credentials. For me the error was fixed by not having a / at the end of the URL enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.