+ Start a Discussion
RudiHulsbosRudiHulsbos 

Using 2 controller classes with one visualforce page

Hi All,

 

I have a visualforce page that displays counts of results. The results are calculated from a list of records, based on a selections from the user. I had to split the controller class into 2 due to the number of characters limitation. In the visualforce page i have controller="Recruitement_Dashboard_Controller1", how do i get the results calculated in the second controller class to display? Please see the code below: (i have posted stripped down examples of my code, i need the returned results of all the methods in both classes, where the data list is generated in the first class)

 

 

public class Recruitement_Dashboard_Controller1{


Public Transient List<Invite_Tracking__c> invitetracking;
String Projectdropdown = 'No Project Selected';
String selectedproject;
String Regiondropdown = 'No Region Selected';
String selectedRegion;
String selectedoperatinggroup;
String operatinggroup = 'No Operating Group Selected';
List<Invite_Tracking__c> projectlist;

    Public List<SelectOption> getItems(){ 
        projectlist = [Select Id, Project__c FROM Invite_Tracking__c ];
        List<SelectOption> options = new List<SelectOption>();
      
        options.add(new SelectOption('0', '-None-'));
        options.add(new SelectOption('COO Circle','COO Circle'));
        options.add(new SelectOption('CFO Circle','CFO Circle'));
        options.add(new SelectOption('CMO Circle','CMO Circle'));
        options.add(new SelectOption('CSO Circle','CSO Circle'));

        return options; 
    }
    
    Public String getSelectedProject() { 
        return selectedproject;    
    }   

    Public void setSelectedProject(String selectedproject) { 
        this.selectedproject = selectedproject;     
    }  
     
    Public List<SelectOption> getItems1(){
    
        List<SelectOption> options = new List<SelectOption>();
        
        options.add(new SelectOption('0','-None-'));
        options.add(new SelectOption('C&HT','C&HT'));
        options.add(new SelectOption('Financial Services','Financial Services'));
        options.add(new SelectOption('Health & Public Service','Health & Public Service'));
        options.add(new SelectOption('Other','Other'));
        options.add(new SelectOption('Products','Products'));
        options.add(new SelectOption('Resources','Resources'));
        options.add(new SelectOption('Unknown','Unknown'));    
        return options;
    }
  
    Public String getSelectedoperatinggroup(){
        return selectedoperatinggroup;
    }
  
    Public void setSelectedoperatinggroup(String selectedoperatinggroup){
        this.selectedoperatinggroup= selectedoperatinggroup;
    }
  
    Public List<SelectOption> getItems2(){
    
        List<SelectOption> options = new List<SelectOption>();
        
        options.add(new SelectOption('0','-None-'));
        options.add(new SelectOption('APAC','APAC'));
        options.add(new SelectOption('N America','N America'));
        options.add(new SelectOption('EALA','EALA'));

        return options;
    }
  
    Public String getSelectedregion(){
        return selectedregion;
    }
  
    Public void setSelectedregion(String selectedregion){
        this.selectedregion = selectedregion;
    }   
  
    Public String getOperatingGroup(){
        if(getSelectedoperatinggroup() <> '0'){    
            OperatingGroup = '';//' - ' + getSelectedProdFam();
        }
        else{
            OperatingGroup = ' - No Operating Group Selected';
        }
        
        return OperatingGroup;
    } 
  
    Public List<Invite_Tracking__c> getContacts(){
        if(getSelectedProject() <> '0' && getSelectedoperatinggroup() == '0' && getSelectedregion() == '0'){ 
            invitetracking = [SELECT Id,Project__c,Member__c,Contact__r.Exclude_from_Engagement_Index__c,
                              Contact__r.Member_Invite_Ranking__c,Contact__r.Region__c,Contact__r.FY_Quarter_Acceptance__c,
                              Counter__c, Organization__r.Operating_Group__c, Organization__r.Client_Classification__c,
                              Organization__r.Id, Organization__r.Global_FT_500_Position__c, Organization__r.Revenues_Mil_Value__c,
                              OrganizationId__c FROM Invite_Tracking__c WHERE Project__c = :getSelectedProject() AND 
                              Contact__r.Exclude_from_Engagement_Index__c = FALSE];
            system.debug('invitetracking: '+invitetracking);
        }    
        else
        if(getSelectedProject() <> '0' && getSelectedoperatinggroup() <> '0' && getSelectedregion() == '0'){
            invitetracking = [SELECT Id,Project__c,Member__c,Contact__r.Exclude_from_Engagement_Index__c,
                              Contact__r.Member_Invite_Ranking__c,Contact__r.Region__c,Contact__r.FY_Quarter_Acceptance__c,
                              Counter__c, Organization__r.Operating_Group__c, Organization__r.Client_Classification__c,
                              Organization__r.Id, Organization__r.Global_FT_500_Position__c, Organization__r.Revenues_Mil_Value__c,
                              OrganizationId__c FROM Invite_Tracking__c WHERE Project__c = :getSelectedProject() AND 
                              Contact__r.Exclude_from_Engagement_Index__c = FALSE AND Organization__r.Operating_Group__c = :getSelectedoperatinggroup()];
            system.debug('invitetracking: '+invitetracking);
        }
        else
        if(getSelectedProject() <> '0' && getSelectedoperatinggroup() <> '0' && getSelectedregion() <> '0'){    
            invitetracking = [SELECT Id,Project__c,Member__c,Contact__r.Exclude_from_Engagement_Index__c,
                              Contact__r.Member_Invite_Ranking__c,Contact__r.Region__c,Contact__r.FY_Quarter_Acceptance__c,
                              Counter__c, Organization__r.Operating_Group__c, Organization__r.Client_Classification__c,
                              Organization__r.Id, Organization__r.Global_FT_500_Position__c, Organization__r.Revenues_Mil_Value__c,
                              OrganizationId__c FROM Invite_Tracking__c WHERE Project__c = :getSelectedProject() AND 
                              Contact__r.Exclude_from_Engagement_Index__c = FALSE AND Contact__r.Region__c = :getSelectedregion() ORDER BY Engagement_Index_Sort__c ASC, Total__c DESC];
            system.debug('invitetracking: '+invitetracking);
        }    
        else
        if(getSelectedProject() <> '0' && getSelectedoperatinggroup() == '0' && getSelectedregion() <> '0'){    
            invitetracking = [SELECT Id,Project__c,Member__c,Contact__r.Exclude_from_Engagement_Index__c,
                              Contact__r.Member_Invite_Ranking__c,Contact__r.Region__c,Contact__r.FY_Quarter_Acceptance__c,
                              Counter__c, Organization__r.Operating_Group__c, Organization__r.Client_Classification__c,
                              Organization__r.Id, Organization__r.Global_FT_500_Position__c, Organization__r.Revenues_Mil_Value__c,
                              OrganizationId__c FROM Invite_Tracking__c WHERE project__c= :getSelectedProject() AND Contact__r.Region__c = :getSelectedregion() AND Contact__r.Exclude_from_Engagement_Index__c = FALSE ORDER BY Engagement_Index_Sort__c ASC, Total__c DESC];
            system.debug('invitetracking: '+invitetracking);
        }    
        else
        {
        Projectdropdown = 'No Project Selected';
        }
        
        return invitetracking;
    }
    
    Public PageReference printrecdash(){ 
        //return page.Recruitment_Dashboard_Excel;
        return null;
    }  

    Public PageReference save(){
        return null;
    }
    
    Public PageReference test(){
        getContacts();
        return null;
    }


 
//Accenture COO List **********************************************************************************************************//    
//Global Counts****************************************************************************************************************//    
    Public Integer getAcceptedMemberCount(){
    getContacts();
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Member__c == 'Community Member' && it.Contact__r.Member_Invite_Ranking__c == '1')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    } 
    
    Public Integer getPendingAccentureTeamCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if((it.Member__c == 'Pending - Accenture Team - invite extended' || it.Member__c == 'Pending - Accenture Team - contacted assistant' || it.Member__c == 'Pending - Accenture Team - currently unable to reach') && (it.Contact__r.Member_Invite_Ranking__c == '2.1' || it.Contact__r.Member_Invite_Ranking__c == '2.2' || it.Contact__r.Member_Invite_Ranking__c == '2.3'))
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    
    Public Integer getPendingCentralizedProcessCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if((it.Member__c == 'Pending - Centralized Process - invite extended' || it.Member__c == 'Pending - Centralized Process - contacted assistant' || it.Member__c == 'Pending - Centralized Process - currently unable to reach') && (it.Contact__r.Member_Invite_Ranking__c == '3.1' || it.Contact__r.Member_Invite_Ranking__c == '3.2' || it.Contact__r.Member_Invite_Ranking__c == '3.3'))
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    
    Public Integer getPendingInvitePOCTBDCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Member__c == 'Pending – Invite POC TBD' && it.Contact__r.Member_Invite_Ranking__c == '4')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    
    Public Integer getDeclinedCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Member__c == 'Declined' && it.Contact__r.Member_Invite_Ranking__c == '5')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    
    Public Integer getOnholdCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Member__c == 'On hold' && it.Contact__r.Member_Invite_Ranking__c == '6')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    
    Public Integer getApprovalRequiredNewExistingCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if((it.Member__c == 'Approval Required - Existing Target' || it.Member__c == 'Approval Required - New Target') && (it.Contact__r.Member_Invite_Ranking__c == '8.1' || it.Contact__r.Member_Invite_Ranking__c == '8.2'))
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    
    Public Integer getArbitratingCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if((it.Member__c == 'Arbitrating - Account' || it.Member__c == 'Arbitrating - Target') && (it.Contact__r.Member_Invite_Ranking__c == '7.1' || it.Contact__r.Member_Invite_Ranking__c == '7.2'))
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    
    Public Integer getFormerCommunityMemberCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if((it.Member__c == 'COO Circle Alumni' || it.Member__c == 'Former Community Member') && (it.Contact__r.Member_Invite_Ranking__c == '10' || it.Contact__r.Member_Invite_Ranking__c == '11'))
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    
    Public Integer getNolongerpursuingCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Member__c == 'No longer pursuing' && it.Contact__r.Member_Invite_Ranking__c == '12')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    
    Public Integer getCurrentlyInvestigatingCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Member__c == 'Currently Investigating' && it.Contact__r.Member_Invite_Ranking__c == '9')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }

//NA Counts *******************************************************************************************************************//
    
    Public Integer getNA_AcceptedMemberCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Member__c == 'Community Member' && it.Contact__r.Member_Invite_Ranking__c == '1' && it.Contact__r.Region__c == 'N America')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }
    

}

 

public class Recruitement_Dashboard_Controller2{

Public Transient List<Invite_Tracking__c> invitetracking;
    
    public Recruitement_Dashboard_Controller2(Recruitement_Dashboard_Controller1 custController) {
        invitetracking = custController.invitetracking;
        system.debug('invitetracking: '+invitetracking);
    }

//Recruits by by Operating Group **********************************************************************************************//    
//Recruiting ******************************************************************************************************************//    
    
    Public Integer getROGR_CHTCount(List<Invite_Tracking__c> invitetracking){
    system.debug('invitetracking: '+invitetracking);
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Organization__r.Operating_Group__c == 'C&HT' && it.Contact__r.Member_Invite_Ranking__c != '1')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }

    Public Integer getROGR_FSCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Organization__r.Operating_Group__c == 'Financial Services' && it.Contact__r.Member_Invite_Ranking__c != '1')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }

    Public Integer getROGR_PRODCount(){
        Integer counter = 0;
        
        for(Invite_Tracking__c it : invitetracking){
            if(it.Organization__r.Operating_Group__c == 'Products' && it.Contact__r.Member_Invite_Ranking__c != '1')
            counter += it.Counter__c.intValue();
        }
        system.debug('counter: '+counter);
        return counter;
    }


}

 

 

<apex:page controller="Recruitement_Dashboard_Controller1" extensions="Recruitement_Dashboard_Controller2" showheader="true" sidebar="false" tabStyle="Recruitment_Dashboard__tab" >

 

I get the following error: 

 

System.NullPointerException: Attempt to de-reference a null object 

Class.Recruitement_Dashboard_Controller2.getROGR_CHTCount: line 159, column 37 External entry point

 

How do i get this working?

 

Thanks,

 

Rudi

imuino2imuino2

 

 public Recruitement_Dashboard_Controller2(Recruitement_Dashboard_Controller1 custController) {
        invitetracking = custController.invitetracking;
        system.debug('invitetracking: '+invitetracking);
    }

 

 

change that code i think the problem there is that you arent initializing the first controller, so it is null.

Try

    Recruitement_Dashboard_Controller1 custController = new Recruitement_Dashboard_Controller1 ();

And take the constructor parameter out.

ahab1372ahab1372

try 

 

 

 public Recruitement_Dashboard_Controller2(Recruitement_Dashboard_Controller1 custController) {
        Recruitement_Dashboard_Controller1 controller1 = custController;
        system.debug('invitetracking: '+invitetracking);
        invitetracking = controller1.invitetracking;
        system.debug('invitetracking: '+invitetracking);
}