2

I have a VisualForce page that it is possible to use offline because I am caching the page and other resources in the application cache.

I have a button on that page that will execute a Visualforce remoting method (intended to work when the user is online).

The issue I have is that if the user has started the application while offline, then they won't be logged into salesforce. When they go back online again, the Visualforce remoting function will execute, but because they are no logged in, an error will be returned.

Is there a solid way, using JavaScript, that I could detect whether the user is currently logged into Salesforce?

If so, is there a way that I could determine the page that they go to after they log in? In an ideal world, the remoting method would execute as normal, but I'd settle for returning to the view that they were on when they pressed the button.

Thanks

  • 4
    I suspect the only way you will be able to validate a session is to make an API call of some sort to Salesforce and handle the invalid session error that results. If you detect an error you can redirect the user to the login page and specify a landing page. – Daniel Ballinger Jul 14 '14 at 20:59
  • 1
    @DanielBallinger This is what I'd say, too. Why don't you post it as the answer? – sfdcfox Jul 15 '14 at 3:45
1

I suspect the only way you will be able to validate a session is to make an API call of some sort to Salesforce and handle the invalid session error that results.

You could try keeping track of how old the Session is, but ultimately you will only know when you call out to Salesforce. E.g. An explicit call to logout elsewhere will invalidate a session before it expires.

If you detect an error you can redirect the user to the login page and specify a landing page.

With a valid SessionID you can bounce users along with a URL like:

https://pod.salesforce.com/secur/frontdoor.jsp?sid=session_id&retURL=start_page

0

" When they go back online again, the Visualforce remoting function will execute, but because they are no logged in, an error will be returned." The returned error must be related with invalid session and the error code must be a constant, e.g.: 404. You can redirect to login view when this error happens.

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.