Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I want my application to process jobs and send API REST requests to my APEX endpoints, which OAuth2 authorization/grant method should I use?

  • If I use authorization_code, then the browser needs to redirect (to Salesforce login page) and the user needs to confirm access. (This would be wrong right?).

I think that I would want to use grant_type : password

If I use password, then I can just set my organizations administration username and password in my application and use that.

I plan on batching up some requests and sending through gearman as a background process.

share|improve this question

I solved with this approach:

  1. use grant_type = authorization_code the first time and ACCESS_TYPE=offline.
  2. save the AccesToken and the RefreshToken in a custom setting.
  3. Start the background job and everytime the job starts, ask for a new token using the refresh token and grant_type = refresh_token.

You have all the documentation in google to do this. Look for "Using a refresh token"

share|improve this answer
If you save the token, do you also save the instance URL that you should be using to send your REST requests? – Layke Feb 25 '14 at 11:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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