I'm learning integrations and found out about named credentials. I want to set a named credential for my Apex method which performs a callout to my scratch org:

  public static List<Object> restCallout(){
    Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setHeader('Authorization', 'Bearer abcdef123456}');
    HttpResponse res = h.send(req);
    List<Object> objs = (List<Object>)JSON.deserializeUntyped(res.getBody());
    return objs;

Scratch org web service:

global class WebServiceFactory {
    global static void getRecord() {
        List<JSONFactory> JSONs = new List<JSONFactory>();
        for(integer i = 0; i<15; i++){
            JSONs.add(new JSONFactory(i, 'Jan' + i, 'Test' + i));
            RestContext.response.responseBody = Blob.valueOf(JSON.serialize(JSONs));

I am slightly confused about which Identity Type and Protocol to choose, so that I can avoid typing this line:

req.setHeader('Authorization', 'Bearer abcdef123456}');

Identity Type options:

  • Anonymous
  • Per user
  • Named principal

Protocol options:

  • OAuth 2.0
  • Password Authentification
  • AWS Signature Version 4
  • JWT
  • JWT Token Exchange

Could anyone give me a hint?

1 Answer 1


For a Salesforce to Salesforce connection, use Per user or Named principal with OAuth 2.0 or JWT. The Identity Type "Per user" allows each user in your org to authenticate with a user in the Scratch Org, while "Named principal" uses a single login (what you'd call an "integration user"). Using the Protocol "OAuth 2.0" uses a simple web-based flow to obtain a token, while JWT uses a command-line tool and security certificates, as outlined in the documentation. The most typical configuration is probably Named principal with OAuth 2.0 in most cases.

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.