KeepAlive Sessions in Salesforce Experience Cloud¶
This page documents how we implemented a session keep-alive strategy for our Salesforce Experience Cloud site, and how to maintain it over time.
Testing Results¶
This method has been tested but does not resolve the issue of users being logged out prematurely. Further investigation and alternative solutions may be required.
Why We Did This¶
By default, users are logged out of our Experience Cloud site after 24 hours of inactivity. We wanted to improve the user experience by reducing the frequency of session timeouts, especially for members who leave a tab open for long periods.
How It Works¶
We created a lightweight Aura component called keepAlive
, which silently pings a no-op Apex method (KeepAliveController.ping()
) every 10 minutes. This keeps the user session active as long as the tab remains open.
- Component Name:
keepAlive
- Apex Controller:
KeepAliveController
- Ping Interval: 10 minutes
- Location: The component is added to the site's shared header layout to ensure it runs on all pages.
How We Built It¶
-
Created Apex Class:
KeepAliveController
- Public, static, and marked
@AuraEnabled
- Contains an empty
ping()
method
- Public, static, and marked
-
Created Aura Component:
keepAlive
- On page load, starts a JS
setInterval
timer that callsKeepAliveController.ping()
every 10 minutes - Logs results to the browser console for debugging
- On page load, starts a JS
-
Added the component to the site header in Experience Builder
- Ensures it loads on every page without duplicating it per page
-
Tested in browser using DevTools (Console + Network tabs)
Maintaining Apex Class Access¶
If new user profiles are added, or users report seeing this error in the Development Tools Console:
"You do not have access to the Apex class named 'KeepAliveController'"
…then you need to grant access to the Apex class. Here's how:
🔧 Steps to Update Profile > Apex Class Access¶
- Go to Setup > Profiles
- Find and click on the profile name (e.g.
SM Community Plus Member
) - Scroll down to Apex Class Access
- Click Edit
- Move
KeepAliveController
from the Available list to the Enabled list - Click Save
Verifying It's Working¶
- Open the browser's DevTools > Console
- Look for log messages like:
[KeepAlive] Pinging server to keep session alive… [KeepAlive] Ping response: SUCCESS
- Visit Setup > Session Management to view real-time session activity
Contact¶
If you're troubleshooting this feature or extending it, contact webdev@spokanemountaineers.org or check the source code in our GitHub repository.