function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ranu Agarwal iBirdsRanu Agarwal iBirds 

How to solve issue of session alive when using action poller?

I am using action poller on my visualforce page, that keep session alive, but if user profile's set up particular hours for timeout then that's not happening here.
Due to action poller, session alive and user's not logged out. 
How can we fix that? Please help ASAP.
nagendra 6989nagendra 6989

Dear Ranu Agarwal iBirds,

Please find the above in order to solve the issue of session alive,.

The ideal behaviour would be similiar to that of a standard VF page: 
1. Renew the session to prevent session timeouts 
2. In the event an exception occurs during the ajax request, the response should be handled similar to a standard VF page. 

At minimum, we should be handling the error more gracefully e.g. a redirect to the login page.
Repro
In any org with a site and authenticate (portal) users configured: 
1. Create a VF page and controller. Example: 
a. Sample Controller: 
public class MyPortalPageController { 
Integer count = { get;set}; 

public PageReference incrementCounter() { 
count++; 
return null; 


b. Sample Page: 
<apex:page controller="MyPortalPageController"> 
<apex:form > 
<apex:outputPanel id="myPanel"> 
<apex:outputText value="Last Refresh:{!NOW()}" /><br/> 
<apex:outputText value="Count:{!count}" /> 
</apex:outputPanel> 
<apex:actionPoller action="{!incrementCounter}" rerender="myPanel" interval="10" /> 
</apex:form> 
</apex:page> 
2. Modify the portal user's profile to include the visualforce page (Enabled Visualforce Page Access). The guest user should not have access to this page. 
3. Reduce the session timeout for the org to a lower limit (e.g. 15 mins). 
3. Login as the portal user through the site, and open the VF page. 
4. *ISSUE* The session will eventually timeout, even though the poller should keep the session alive, as per the documentation (http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionPoller.htm). 
5. *ISSUE* The ajax poller is failing silently with a 401 error. Checking the browser console (XHR), the response returned is 401, and the page is not affected or redirected. 
6. As the session has expired, each subsequent failed ajax call contributes towards the page view limit, which as deemed Working as Designed.
Workaround
Try using an "actionFunction" instead of an actionPoller, and use native client-side javascript to trigger the polling. 

From page: 
========= 
<apex:page controller="exampleCon"> 
<apex:form > 
<apex:outputText value="Watch this counter: {!count}" id="counter"/> 
<apex:actionPoller action="{!incrementCounter}" rerender="counter" interval="5"/> 
<br></br> 
{!$Api.Session_ID} 
</apex:form> 
</apex:page> 

To page: 
======= 
<apex:page controller="exampleCon"> 
<apex:form > 
<apex:outputText value="Watch this counter: {!count}" id="counter"/> 
<apex:actionFunction name="myPollingFunc" action="{!incrementCounter}" rerender="counter"/> 
<script type="text/javascript"> 
//use the native javascript setInterval to trigger the function - first argument is javascript function, second is the interval in milliseconds 
setInterval(myPollingFunc,5000); 
</script> 
</apex:form> 
</apex:page> 

It should hopefully redirect the user to the portal login page, providing the page that contains the actionFunction isn't accessible to a guest user.

Mark it as solved if it helps you.........
Thanks & Regards
Nagendra.P
9848950830