Named credentials are working good in single user scenario, where we are making callouts on behalf of a given user.

In a recent requirement, we need to setup a "PER USER" Named Credential, which requires each user to login and authorize separately.

The same Named Credential needs to be consumed in a Salesforce batch job, where we will sync up data of multiple users every mid night.

I am not able to figure out a way to make the a HTTP callout in Apex, and making that Named Credential work for a given user. Is it possible ?

If you believe the problem can't be solved, please up-vote this related idea : https://success.salesforce.com/ideaView?id=0873A000000E3exQAC

  • 2
    Tough one! Could a feasible workaround be using an Inbound Email Service to start the various jobs and the context of the correct user? Commented Sep 7, 2016 at 7:16
  • Not sure but this blog also use per user auth in apex Commented Sep 7, 2016 at 7:17
  • 1
    @bigassforce cool trick, but sending multiple emails to all inbound users will not work, we are doing it for AppExchange. If NamedCredentials fail for this basic usecase, I might need to fall back to class DIY OAuth 2 :-( Commented Sep 7, 2016 at 8:21
  • 2
    I think original problem here is you cannot run an apex batch apex with specific user . Wondering if a class scheduled via standard UI can have user context Commented Sep 7, 2016 at 8:26
  • 1
    Here is link to the idea: success.salesforce.com/ideaView?id=0873A000000E3exQAC Commented Sep 8, 2016 at 3:55


You must log in to answer this question.

Browse other questions tagged .