2

In our application when user clicks at specific button on the page http callout to external service is triggered from apex code on the server side. As one of the parameters we are passing session id to this external service, since it needs to have access to the org to read some info through Rest API and create some data as well. It takes usually couple minutes for external service to do its job.

This approach of sharing session id works in general. But the problem appears when user logs out right after initiating callout. This invalidates the session, so external service immediately loses access to the org.

Is there anyway to get session id which would not be invalidated on user log out? Any other better approaches how to give access to external service to org under current user?

3
  • 2
    What you need is an OAuth session, so that you have a separate session to work with. Even if the user logs out of the browser, their OAuth session will persist. – sfdcfox Jan 11 '18 at 17:01
  • @sfdcfox I'm a bit confused, cause here we have kinda reverse direction of communication, i.e. from SF to external service. OAuth usually follows the schema when you have another website with UI and your user logs in from there to SF granting some permissions with the help of tokens etc. But here we are initiating request from SF to our node js app hosted on heroku. The app puts user request in the queue, and later on needs to be able to connect to SF instance and process some data there. We are trying to avoid passing username and password in request. Would OAuth still be an option here? – wesaw Jan 11 '18 at 17:16
  • 2
    what I'd do is have the user redirect to the heroku app, and it captures a session Id via Oauth, then go back to Salesforce. From there, you have your session Id. Alternately, consider using Outbound Messaging, which provides a valid session UD even if there user is logged out. – sfdcfox Jan 11 '18 at 17:22

Your Answer

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

Browse other questions tagged or ask your own question.