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

I have a basic question about Salesforce session: How can I logout my users automatically when they close the browser window?

share|improve this question
I don't know of a way to do it with native pages. The only work around I can think of would be to make the timeout value really short (15 minutes). This of course adds a usability problem for your users if they leave a session inactive. – Daniel Hoechst Dec 12 '12 at 15:26
What if the user opens multiple tabs/windows? Do you log them out if they close just one of the tabs/windows? Is there any reliable way to know when they've closed all tabs/windows? Why do you want to log them out automatically? – tomlogic Dec 13 '12 at 6:25

Well, to log a user out you redirect them to /secur/logout.jsp ... however enforcing that mechanism would either have to be done via JavaScript or in theory you could also use a Browser Extension

share|improve this answer

I think if we talk about custom pages then by using JS this may be possible (that also need POC), but other than that it is quite impossible to do this with all native pages (home page component can help?).

share|improve this answer

I see this is an old thread but I thought I would share a workaround I discovered ...

Add a controller to your site home page, and in the init action, redirect to secure page, if it is not already a secure page.

public PageReference init() {
        String currentURL = Site.getCurrentSiteUrl();
        if (!startsWith(currentUrl, 'https://')) {
            return redirect(currentURL.replace('http://', 'https://'));

        return null;

Link to the thread HERE

share|improve this answer
This doesn't seem to logout users at all, but rather force them to use the HTTPS version of salesforce, and then only works on Sites - it wouldn't work for internal salesforce users. – ca_peterson Oct 2 '13 at 20:10

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.