+ Start a Discussion
Manjunath reddy 25Manjunath reddy 25 

Not able to access the variable from catch block, please help me on this.

Hi All,
I need help on the issue with my VF page, My VF page code and my controller code is as below.in the below code in y controller, I have created a boolean variable called dupRecord,which I made true in the catch block, I am trying to access dupRecord variable in the method in the closingTheTab method., as per debug logs, I am able to get dupRecord is true in the catch block, but Iam not able to get dupRecord variable as true in closingTheTab method, Iam trying to send dupRecord variable from apex;:param to duprecord2, but I am not gettting expected result, before that, I just made the dupRecord as true in catch block and tried accessin in the closingTheTab , but not able to get expected result, please help me on this.
<apex:page standardController="HPE_Account_Team__c" extensions="GSDAccountteammembercontroller" sidebar="false" showHeader="false">
<apex:pagemessages id="EMSG"/>
<apex:includeScript value="/support/console/33.0/integration.js"/>
<script type="text/javascript">
    
        function RefreshPrimaryTab() 
        {
            //var primaryTabId = 'navigatortab__scc-pt-1';
            sforce.console.getFocusedPrimaryTabId(showTabId);
        }
            
        var showTabId = function showTabId(result) 
        {
            var tabId = result.id;
            sforce.console.refreshPrimaryTabById(tabId , true, refreshSuccess);
        };
        
        var refreshSuccess = function refreshSuccess(result) 
        {
            //Report whether refreshing the primary tab was successful
            if (result.success == true) 
            {
                alert('Primary tab refreshed successfully');
            } 
            else 
            {
                alert('Primary did not refresh');
            }
        };          


function ClosetheTab() {        
    if(sforce.console.isInConsole()) {
        sforce.console.getEnclosingTabId(closeSubtab);
        //var primaryTabId = 'navigatortab__scc-pt-1';
        sforce.console.getFocusedPrimaryTabId(showTabId);
        }
        else{
        alert('hello it is out of console');
        //window.location.href = location.protocol + '//' + window.location.hostname + '/' + '{!parentrecordid}';
        //window.location.href = window.opener.location.href;
        window.opener.refreshoutofconsole();
        alert('hello it is out of console2');
        window.top.close();

        }
    } 
    var closeSubtab = function closeSubtab(result) {

        //Now that we have the tab ID, we can close it
        var tabId = result.id;
        sforce.console.closeTab(tabId);
    };

function CloseSavePage(TabToBeClosed){
    alert('Now it is reached to CloseSavePage function');
    alert(TabToBeClosed);
    //TabToBeClosed=true;
    //alert(TabToBeClosed);
    if(TabToBeClosed==='true'){
        ClosetheTab();
    }
    alert('Now it is reached to ClosetheTab function');
}

function CloseTaboncancel() {        
    if(sforce.console.isInConsole()) {
          sforce.console.getEnclosingTabId(closeSubtab);
        }
        else{
        window.top.close();
    }
}
</script>
    <apex:form >
        <apex:actionFunction name="priorityChangedJavaScript"   action="{!closingtheTab}" oncomplete="CloseSavePage('{!TabToBeClosed}');return false"/ > 
                    <apex:pageblock >            
            <apex:pageBlockTable value="{!listofrecords}" var="Acc" id="pbt">
            <apex:column headerValue="Name" style="width:250px">
                <apex:inputField value="{!Acc.Name__c}" required="false" />
            </apex:column>
            <apex:column headerValue="Role">
                <apex:inputField value="{!Acc.Role__c}" required="false"/>
            </apex:column>
            <apex:column headerValue="Role Scope">
                <apex:inputField value="{!Acc.Role_Scope__c}" required="false"/>
            </apex:column>
            <apex:column headerValue="Role Scope Description">
                <apex:inputField value="{!Acc.Role_Scope_Description__c}" style="width:600px"/>
            </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
            
            <apex:commandButton action="{!SaveRecords}" value="Save" reRender="Pbt,EMSG"  onclick="priorityChangedJavaScript()">
                {!dupRecord};
            {!dupRecord2};
                <apex:param value="{!dupRecord}" assignTo="{!dupRecord2}"/>
                {!dupRecord};
            {!dupRecord2};
             </apex:commandButton>
            
                <apex:commandButton value="Cancel" onclick="CloseTaboncancel()"/>
            </apex:pageBlockButtons>
        </apex:pageblock>
    </apex:form>
</apex:page>
 
public  class GSDAccountteammembercontroller {
    public list<HPE_Account_Team__c> listofrecords{get;set;}
    public Boolean TabToBeClosed {get;set;}
    public string parentrecordid{get;set;}
    public HPE_Account_Team__c HPEAccountTeam{get;set;} 
    public string recieveID{get;set;}
    public string currentAccountPageId{get;set;}
    public boolean dupRecord{get;set;}
    public boolean dupRecord2{get;set;}
    
    
    //Constructor
    public GSDAccountteammembercontroller(ApexPages.StandardController controller){
        //tabTobeClosed = true;
        dupRecord=false;
        dupRecord2=false;
        parentrecordid = ApexPages.currentPage().getParameters().get('Account__c');//this line is for when the record is coming from the ASDP page
        recieveID= ApexPages.currentPage().getParameters().get('sendasdpid');
        system.debug('recieveID'+recieveID);
        system.debug('parentrecordid'+parentrecordid);
        HPEAccountTeam=(HPE_Account_Team__c)controller.getrecord();
        system.debug('HPEAccountTeam.id'+HPEAccountTeam.id);
        if(HPEAccountTeam.account__c!=null){
            recieveID=HPEAccountTeam.account__c;
        }
        system.debug('HPEAccountTeam'+HPEAccountTeam);
        currentAccountPageId= ApexPages.currentPage().getParameters().get('id');
        system.debug('currentAccountPageId'+currentAccountPageId);
        if(parentrecordid == null || parentrecordid == ''){
        system.debug('Enter parentrecordid '+parentrecordid );
                parentrecordid = HPEAccountTeam.Account__c;
                system.debug('Enter parentrecordid '+parentrecordid );
        }
              
        HPE_Account_Team__c accteam;
        //tabToBeClosed = false;
        listofrecords = new list<HPE_Account_Team__c>();
            for(Integer i=accountConstants.Zero; i<accountConstants.Five ; i++){   
                accteam = new HPE_Account_Team__c();       
                listofrecords.add(accteam);
             }
     } 
      
      
    //Save method 
    public PageReference SaveRecords() {
        list<HPE_Account_Team__c> AccountTeamtoBeInserted= new list<HPE_Account_Team__c>(); 
        try{
         //tabToBeClosed = true;
          system.debug('Save parentrecordid '+parentrecordid );
          
            for(HPE_Account_Team__c acctem :listofrecords){
                acctem.Account__c = parentrecordid;
                if(acctem.Name__c!= null && acctem.Role__c!=null && acctem.Role_Scope__c!=null ){
                    AccountTeamtoBeInserted.add(acctem);
                }
                else if(acctem.Name__c != null || acctem.Role__c!=null || acctem.Role_Scope__c!=null ){
                   ApexPages.Message errorMessage= new ApexPages.Message(ApexPages.Severity.ERROR, Label.GSD_Account_Error_Message);ApexPages.addMessage(errorMessage);
                   return null; 
                }
             }
                if(AccountTeamtoBeInserted.size() > 0)
                    insert AccountTeamtoBeInserted;
                else{
                    ApexPages.Message errorMessage= new ApexPages.Message(ApexPages.Severity.ERROR, Label.GSD_Account_Error_Message);ApexPages.addMessage(errorMessage);
                    //tabTobeClosed = false;
                    return null; 
                }
        }
        catch(Exception ex){           
             ApexPages.addMessages(ex);
             //tabTobeClosed = false;
             dupRecord= true;
             system.debug('dupRecord' +dupRecord);
             return null;
         }    
            
        string BaseURL = URL.getSalesforceBaseUrl().toExternalForm();
        system.debug('recieveID'+recieveID); 
             PageReference redirectTopage = new PageReference(BaseURL+'/'+recieveID);
             redirectTopage.setRedirect(true);
             return redirectTopage;
    }
    
    public void closingtheTab(){
        system.debug('The value is before making true' +tabToBeClosed);  
        system.debug('dupRecord2' +dupRecord);  
         for(HPE_Account_Team__c acctem :listofrecords){
                if(acctem.Name__c!= null && acctem.Role__c!=null && acctem.Role_Scope__c!=null ){
                    system.debug('tabToBeClosed' +tabToBeClosed);
                    tabToBeClosed = true;
                    system.debug('tabToBeClosed' +tabToBeClosed);
                    system.debug('dupRecord' +dupRecord);
                    if(dupRecord2==true){
                        tabToBeClosed = false;
                    }
                    break;
                } 
                else if(acctem.Name__c == null || acctem.Role__c == null || acctem.Role_Scope__c == null ){
                    system.debug('tabToBeClosed' +tabToBeClosed);
                    tabToBeClosed = false;
                }
         }
        system.debug('The value is after making true' +tabToBeClosed);
        
    }

}