+ Start a Discussion
raj kiranraj kiran 

Visualforce remoting Manager issue

Hi All, 

In my org, when ever user logs in, we have custom home components,in custom home components we have created  a vf page and have written logic is such a way that whenever user logs in, we check if its the new session from UserInfo.getSessionId to that of store the old sessionid  in objectB. we compare when ever user logs in and based on some flags fields we populate users a custom docuement accordingly.

if the flags are true it would present a docuement or else page will just refresh only once and rest is normal.

My issue is that for a single person in my org the page is getting refreshed again and again. when he clicks on opportunity or account tab the screen gets refreshed back to home page tab. ideally this should not happen.

this is my vf page :

<apex:page id="hompage" title="Homepage Visualforce" showheader="false" sidebar="false" cache="false" standardStylesheets="false" controller="SalesCompRemote">
<script type="text/javascript"> function getRemoteSalesComp()
var userId = '{!$User.Id}';
'{!$RemoteAction.SalesCompRemote.getRedirect}', userId,
function(result, event)
{ if (event.status )
if(result == true)
parent.parent.location.href = "/apex/SalesCompDefaultLandingPage?tsid={!$CurrentPage.parameters.tsid}";
{escape: true} ); } </script> <body onload="getRemoteSalesComp();"> </body> </apex:page>

the above mentioned vf is called/invoked for an ideal time about 2 min . like if user is idle for 2-5 minutes and if clicks on accounts tab, the screen gets refreshed back to home tab.  As per above code the user who is facing the iusse has the event value as false. so idealy the check should happen only once per login but here its happening again and specially on user clicks.

here is the controller : global class SalesCompRemote {

    public SalesCompRemote(){ }
    global static Boolean getRedirect(String EmployeeId){
        system.debug('****INSIDE REMOTE METHOD****');
        Boolean redirect = False;
        Date CurrentDateStamp = Date.Today();
        system.debug('Line no 520 EmployeeId'+ EmployeeId);
        List<Sales_Compensation__c> SalesCompUpdate = new List<Sales_Compensation__c>();
        List<Sales_Compensation__c> SalescompRecList = [Select Id,  Session_Id__c FROM Sales_Compensation__c WHERE Status__c ='New' AND Template__c != null AND Start_Date__c <= :CurrentDateStamp AND Effective_Date__c != null AND Employee__c =:EmployeeId];
        Database.Saveresult[] updSave = new Database.Saveresult[]{};
            system.debug('UPDATE SESSION ID FOR ALL OPEN RECORDS');
            for(Sales_Compensation__c localRec :SalescompRecList ){                
                system.debug('Saved Session Id ' + localRec.Session_Id__c);
                system.debug('System Session Id'+UserInfo.getSessionId());              
                if(localRec.Session_Id__c <> UserInfo.getSessionId()){              
                    //redirect = True;
                    localRec.Session_Id__c = UserInfo.getSessionId();
            updSave = Database.Update(SalesCompUpdate,false);            
            system.debug('update Save Result'+updSave); 
        List<Sales_Compensation__c> SalescompAckRecList = [Select Id,  Session_Id__c FROM Sales_Compensation__c WHERE Status__c ='New' AND Template__c != null AND Start_Date__c <= :CurrentDateStamp AND Effective_Date__c != null AND Employee__c =:EmployeeId ORDER BY End_Date__c NULLS LAST, Start_Date__c DESC LIMIT 1];
        if(!SalescompAckRecList.isEmpty() && !SalesCompUpdate.isEmpty() && !updSave.isEmpty()){
            for(Sales_Compensation__c compRec :SalescompAckRecList){
                if(compRec.Session_Id__c == UserInfo.getSessionId()){
                   redirect = True;
        return redirect;