+ Start a Discussion
Jean Grey 10Jean Grey 10 

Display Accounts with Related Data on Visualforce Page

I'm trying to display Accounts on a Visualforce page with counts of tasks, leads, opps, owners, etc. I believe have all of the data in my controller but I'm not sure how to connect each variable to the appropriate account. Is Wrapper class the correct approach? What about a map? If anyone can share an idea or documentation that I could learn from it would be much appreciated.
public class WrapperDemoController{
    	//variables to hold all related data
		public Set<Id> accSet {get;set;}
		public List<Account> accList {get;set;}
		public Set<Id> conSet {get;set;}
		public List<Contact> conList {get;set;}
		public Set<Id> leadSet {get;set;}
		public List<Lead> leadList {get;set;}
		public List<Lead> leadListAll {get;set;}
		public DateTime nowDate {get;set;}
		public Date todayDate {get;set;}
		public Set<Id> whoSet {get;set;}
		public Set<Id> whatSet {get;set;}
		public Set<Id> ocrSet {get;set;}
		public List<OpportunityContactRole> ocrList {get;set;}
		public List<Opportunity> oppList {get;set;}
		public Set<Id> oppSet {get;set;}
		public Set<Id> taskSet {get;set;}
		public List<Task> taskList {get;set;}
		public Set<Id> repSet {get;set;}
		public List<User> repList {get;set;}
	    /*Our Wrapper Class*/
	    public class TableRow{
	        public String accName {get;set;}
	        public String domain {get;set;}
	        public Integer countLeads {get;set;}
	        public Integer countOpenTasks {get;set;}
	        public Integer countReps {get;set;}
	        public Integer countOpenOpps {get;set;}
	        public Integer countExistingTasks {get;set;}
	    }
	   
	    /*Public Property that will hold all the TableRows and our PageBlockTable can use this Variable to get the whole List of rows*/
	    public List<TableRow> rowList {get; set;}

	    /*Constructor that runs a SOQL to get all the Records and build the List. This get executed automatically on the Page Load.*/
	    public WrapperDemoController(){
	    	nowDate = system.now();
	    	todayDate = system.today();

	        rowList = new List<TableRow>();
	        TableRow tr;

	        //Sets
	        whoSet = new Set<Id>();
	        accSet = new Set<Id>();
	        whatSet = new Set<Id>();
	        conSet = new  Set<Id>();
	        leadSet = new Set<Id>();
	        ocrSet = new Set<Id>();
	        oppSet = new Set<Id>();
	        repSet = new Set<Id>();
	        //leads that have reporting matched account populated. This will be the list of Accounts we look at
	        leadList = new List<Lead<([SELECT Id,OwnerId,Owner.Name,Matched_Account__c, Matched_Account__r.Name 
	        			FROM Lead WHERE Matched_Account__c!=NULL AND IsConverted=FALSE]);
	        system.debug('leadList '+leadList);
	        //first fill the account set. This is the Set to find all related data
	        for(Lead l : leadList){
	        	accSet.add(l.Matched_Account__r.Id);
	        	whatSet.add(l.Matched_Account__r.Id);
	        	repSet.add(l.OwnerId);
	        }
	        //now get all the leads
	        leadListAll = new List<Lead>([SELECT Id,OwnerId,Owner.Name,Matched_Account__c, Matched_Account__r.Name
	        							FROM Lead WHERE Matched_Account__r.Id IN :accSet]);
	        //now fill the contact list
	        conList = new List<Contact>([SELECT Id,OwnerId,Owner.Name,AccountId,Account.Name FROM Contact WHERE AccountId IN :accSet]);
	        //now use the lead and contact lists to fill the whoSet
	        for(Lead l :leadListAll){
	        	whoSet.add(l.Id);
	        	repSet.add(l.OwnerId);
	        }
	        for(Contact c :conList){
	        	whoSet.add(c.Id);
	        	conSet.add(c.Id);
	        	repSet.add(c.OwnerId);
	        }
	        //find all ocrs related to these contacts or accounts
	        //might need to split into searching by accounts and contacts separately, to avoid SOQL limits
	        ocrList = new List<OpportunityContactRole> ([SELECT Id,OpportunityId,ContactId,Contact.AccountId,Opportunity.StageName,Opportunity.Amount 
                                                     FROM OpportunityContactRole 
                                                     WHERE Opportunity.StageName !='Duplicate Quote' AND IsClosed=FALSE AND
                                                     (ContactId IN :conSet OR Contact.AccountId IN :accSet)]);
	        for(OpportunityContactRole ocr :ocrList){
	        	oppSet.add(ocr.OpportunityId);
	        	conSet.add(ocr.ContactId);
	        	whoSet.add(ocr.ContactId);
	        	whatSet.add(ocr.OpportunityId);
	        	whatSet.add(ocr.Contact.AccountId);
	        	accSet.add(ocr.Contact.AccountId);
	        	repSet.add(ocr.Contact.OwnerId);
	        	repSet.add(ocr.Contact.Account.OwnerId);
	        	repSet.add(ocr.Opportunity.OwnerId);
	        }
	        //find all opps by account
	        oppList = new List<Opportunity>([SELECT Id,StageName,Amount,OwnerId,Owner.Name FROM Opportunity 
	        	WHERE IsClosed=FALSE AND CloseDate>:todayDate AND AccountId IN :accSet]);
	        for(Opportunity o :oppList){
	        	oppSet.add(o.Id);
	        	whatSet.add(o.Id);
	        	repSet.add(o.OwnerId);
	        }
	        //now find all open tasks related to any above data
	        taskList = 
	        [SELECT Id,OwnerId,WhoId,WhatId FROM Tasks WHERE Status!='Completed' AND ActivityDate>:todayDate AND 
	        (Type = 'Call/Email' OR Type = 'Call_Email' OR Type = 'Call:TT' OR Type = 'Call:LM' OR Type = 'Call:Demo' OR Type = 'Call:Other' OR Type = 'Follow_up' OR Type = 'Follow up')
	        AND (WhoId IN :whoSet OR WhatId IN :whatSet)];

	        /*Building the List of TableRows*/
	        /*Fetch all the Contacts and then build the List*/
	        for(Account a : accSet){
	            tr = new TableRow();
	            tr.accName = acc.Name;
	            tr.domain = acc.Domain;
	            tr.countLeads = ;
	            tr.countOpenOpps = ;
	            tr.countOpenTasks = ;
	            tr.countReps = ;

	            /*Add the TableRow to the List then and there*/
	            rowList.add(tr);
	        }
	    }
}

 
Best Answer chosen by Jean Grey 10
Abdul KhatriAbdul Khatri
Hi Please let me know if the below code can help you
 
public class WrapperDemoController{
    
    Map<Id, Integer> acctLeadCountMap = new Map<Id, Integer>();
    Map<Id, Set<Id>> acctRepCountMap = new Map<Id, Set<Id>>();
    Map<Id, Integer> acctContactCountMap = new Map<Id, Integer>();
    Map<Id, Integer> acctOpportunityCountMap = new Map<Id, Integer>();
    Map<Id, Integer> acctTaskCountMap = new Map<Id, Integer>();
    Map<Id, Account> accountMap = new Map<Id, Account>();
    AggregateResult[] groupedResults;

    /*Our Wrapper Class*/    
    public class TableRow{
        public String accName {get;set;}
        public String domain {get;set;}
        public Integer countLeads {get;set;}
        public Integer countOpenTasks {get;set;}
        public Integer countReps {get;set;}
        public Integer countOpenOpps {get;set;}
        public Integer countExistingTasks {get;set;}
    } 
    
    /*Public Property that will hold all the TableRows and our PageBlockTable can use this Variable to get the whole List of rows*/
    public List<TableRow> rowList {get; set;}    

    /*Constructor that runs a SOQL to get all the Records and build the List. This get executed automatically on the Page Load.*/
    public WrapperDemoController()
    {    
        groupedResults = [SELECT Matched_Account__c, Count(Id) FROM Lead WHERE Matched_Account__c!=NULL AND IsConverted=FALSE GROUP BY Matched_Account__c];
        for (AggregateResult ar : groupedResults)  {
            acctLeadCountMap.put(ar.get('Matched_Account__c'), ar.get('expr0'));
        }
        
        List<Account> acctList = [SELECT OwnerId, Name, Domain FROM Account WHERE Id = :acctLeadCountMap.keySet()];
        for (Account account : acctList) 
        {
            if(acctRepCountMap.containsKey(account.Id)) {
                Set<Id> idSet = new Set<Id>(acctRepCountMap.get(account.Id));
                idSet.add(account.OwnerId);
                acctRepCountMap.put(account.Id, idSet);
            } else {
                acctRepCountMap.put(account.Id, new Set<Id>{account.OwnerId});
            }
            accountMap.put(account.Id, account);
        }
        
        List<Account> accountList = [Select Id, 
                                        (Select Id From Contacts),                              
                                        (Select Id From Opportunities Where  Opportunity.StageName !='Duplicate Quote' AND IsClosed = false AND CloseDate >: todayDate), 
                                        (SELECT Id From Tasks WHERE Status!='Completed' AND ActivityDate>:todayDate AND 
                                                    (Type = 'Call/Email' OR Type = 'Call_Email' OR Type = 'Call:TT' OR Type = 'Call:LM' OR Type = 'Call:Demo' OR Type = 'Call:Other' OR Type = 'Follow_up' OR Type = 'Follow up')) 
                                    From Account Where Id IN :acctLeadCountMap.keySet()];
        for(Account acctRecord : accountList) {
            
            if(acctRecord.Contacts != null) acctContactCountMap.put(acctRecord.Id, acctRecord.Contacts.size());
            if(acctRecord.Opportunities != null) acctOpportunityCountMap.put(acctRecord.Id, acctRecord.Opportunities.size());
            if(acctRecord.Tasks != null) acctTaskCountMap.put(acctRecord.Id, acctRecord.Tasks.size());    
        }
        
        for(Id idAcct : acctLeadCountMap.keySet())
        {
            tr = new TableRow();
            tr.accName = accountMap.get(idAcct).Name;
            tr.domain = accountMap.get(idAcct).Domain;
            tr.countLeads = acctLeadCountMap.get(idAcct);
            tr.countOpenOpps = acctOpportunityCountMap.get(idAcct);
            tr.countOpenTasks = acctTaskCountMap.get(idAcct);
            tr.countReps = acctRepCountMap.get(idAcct).size();
        
            /*Add the TableRow to the List then and there*/
            rowList.add(tr);
        }
    }
}

 

All Answers

Akshay_DhimanAkshay_Dhiman
Hi Jean,

The wrapper is the best approach for achieving your requirement,
This is an example which helps you -- 
In this way, you can merge all accounts related tasks, leads, opps.
 
public class Aura3Ques {
    @AuraEnabled
    public static List<wrapperuse> acclist()
    {
        List<wrapperuse> wrapobjlist = new List<wrapperuse>();
        List<Account> acclist = new List<Account>();
        acclist=[Select Id,name,(Select id,LastName from Contacts),(Select id,Name from Opportunities) from Account limit 100];
        for(Account accloop : acclist)
        {
            wrapperuse wrapobj = new wrapperuse();
            wrapobj.Name=accloop.Name;
           wrapobj.con= accloop.Contacts;
            wrapobj.opp= accloop.Opportunities;
            wrapobj.contactsize = accloop.Contacts.size();
            wrapobjlist.add(wrapobj);
            
        }
        return wrapobjlist;
        
    }
    public class wrapperuse 
    {
        @AuraEnabled public String Name{get;set;}
       @AuraEnabled public List<Contact> con{get;set;}
        @AuraEnabled public List<Opportunity> opp{get;set;}
        @AuraEnabled public Integer contactsize{get;set;}
    }
}


Thanks 
Akshay
Jean Grey 10Jean Grey 10
Thank you, but I am actually starting from the Matched_Account__c field on lead which is a lookup to account. I need to use this relationship to find all related Leads, Contacts, Opportunities, Tasks, and Users. Is there a way to do so with one SOQL query? If not, how do I group these queries together by Account Id? On my visualforce page I want my first column to be the Account, and each column after to contain all related records of objects mentioned (using that matched Account field on Lead). 
Abdul KhatriAbdul Khatri
Hi Please let me know if the below code can help you
 
public class WrapperDemoController{
    
    Map<Id, Integer> acctLeadCountMap = new Map<Id, Integer>();
    Map<Id, Set<Id>> acctRepCountMap = new Map<Id, Set<Id>>();
    Map<Id, Integer> acctContactCountMap = new Map<Id, Integer>();
    Map<Id, Integer> acctOpportunityCountMap = new Map<Id, Integer>();
    Map<Id, Integer> acctTaskCountMap = new Map<Id, Integer>();
    Map<Id, Account> accountMap = new Map<Id, Account>();
    AggregateResult[] groupedResults;

    /*Our Wrapper Class*/    
    public class TableRow{
        public String accName {get;set;}
        public String domain {get;set;}
        public Integer countLeads {get;set;}
        public Integer countOpenTasks {get;set;}
        public Integer countReps {get;set;}
        public Integer countOpenOpps {get;set;}
        public Integer countExistingTasks {get;set;}
    } 
    
    /*Public Property that will hold all the TableRows and our PageBlockTable can use this Variable to get the whole List of rows*/
    public List<TableRow> rowList {get; set;}    

    /*Constructor that runs a SOQL to get all the Records and build the List. This get executed automatically on the Page Load.*/
    public WrapperDemoController()
    {    
        groupedResults = [SELECT Matched_Account__c, Count(Id) FROM Lead WHERE Matched_Account__c!=NULL AND IsConverted=FALSE GROUP BY Matched_Account__c];
        for (AggregateResult ar : groupedResults)  {
            acctLeadCountMap.put(ar.get('Matched_Account__c'), ar.get('expr0'));
        }
        
        List<Account> acctList = [SELECT OwnerId, Name, Domain FROM Account WHERE Id = :acctLeadCountMap.keySet()];
        for (Account account : acctList) 
        {
            if(acctRepCountMap.containsKey(account.Id)) {
                Set<Id> idSet = new Set<Id>(acctRepCountMap.get(account.Id));
                idSet.add(account.OwnerId);
                acctRepCountMap.put(account.Id, idSet);
            } else {
                acctRepCountMap.put(account.Id, new Set<Id>{account.OwnerId});
            }
            accountMap.put(account.Id, account);
        }
        
        List<Account> accountList = [Select Id, 
                                        (Select Id From Contacts),                              
                                        (Select Id From Opportunities Where  Opportunity.StageName !='Duplicate Quote' AND IsClosed = false AND CloseDate >: todayDate), 
                                        (SELECT Id From Tasks WHERE Status!='Completed' AND ActivityDate>:todayDate AND 
                                                    (Type = 'Call/Email' OR Type = 'Call_Email' OR Type = 'Call:TT' OR Type = 'Call:LM' OR Type = 'Call:Demo' OR Type = 'Call:Other' OR Type = 'Follow_up' OR Type = 'Follow up')) 
                                    From Account Where Id IN :acctLeadCountMap.keySet()];
        for(Account acctRecord : accountList) {
            
            if(acctRecord.Contacts != null) acctContactCountMap.put(acctRecord.Id, acctRecord.Contacts.size());
            if(acctRecord.Opportunities != null) acctOpportunityCountMap.put(acctRecord.Id, acctRecord.Opportunities.size());
            if(acctRecord.Tasks != null) acctTaskCountMap.put(acctRecord.Id, acctRecord.Tasks.size());    
        }
        
        for(Id idAcct : acctLeadCountMap.keySet())
        {
            tr = new TableRow();
            tr.accName = accountMap.get(idAcct).Name;
            tr.domain = accountMap.get(idAcct).Domain;
            tr.countLeads = acctLeadCountMap.get(idAcct);
            tr.countOpenOpps = acctOpportunityCountMap.get(idAcct);
            tr.countOpenTasks = acctTaskCountMap.get(idAcct);
            tr.countReps = acctRepCountMap.get(idAcct).size();
        
            /*Add the TableRow to the List then and there*/
            rowList.add(tr);
        }
    }
}

 
This was selected as the best answer
Jean Grey 10Jean Grey 10
This is very helpful, thank you. All works fine except for Line 30, I get the error "Method does not exist or incorrect signature: void put(Object, Object) from the type Map<Account,Integer>"

I was able to format the integer like so:
object arObj = ar.get('expr0');
integer arInt = integer.valueOf(arObj);
acctLeadCountMap.put(ar.get('Matched_Account__c'),arInt);
But I still get the incorrect signature. Do I need to do some operation to change the matched account object to an ID for the map?
Abdul KhatriAbdul Khatri
Change that to this
 
acctLeadCountMap.put((Id)ar.get('Matched_Account__c'),(Integer)ar.get('expr0'))

 
Jean Grey 10Jean Grey 10
Thanks so much, this is working now. I added some more handling to get additional counts/columns for my page. Updated code is below.

For the rep map (owners), I need to include owners of all records. I have owners for the leads, accounts, contacts and opps, but how do I get the task owners for the tasks that match the contact or lead? Because of the polymorphic restrictions I cannot query on the account field for those two objects. Do I need to create a new map of Contact/Lead to Account (from the main map), and compare in the query? Would it be easier/better design to simply populate the account Id field on all tasks with the account Id (if contact) or matched account id (if lead)?
public class matchedAccounts{
    
    Map<Id, Integer> acctLeadCountMap = new Map<Id, Integer>();
    Map<Id, Integer> prospLeadCountMap = new Map<Id, Integer>();
    Map<Id, Set<Id>> acctRepCountMap = new Map<Id, Set<Id>>();
    Map<Id, Integer> acctContactCountMap = new Map<Id, Integer>();
    Map<Id, Integer> acctOpportunityCountMap = new Map<Id, Integer>();
    Map<Id, Integer> acctTaskCountMap = new Map<Id, Integer>();
    Map<Id, Account> accountMap = new Map<Id, Account>();
      public DateTime nowDate = system.now();
    public Date todayDate = system.today();
    AggregateResult[] groupedResults;

    //Wrapper Class
    public class TableRow{
        public String accName {get;set;}
        public String domain {get;set;}
        public Integer countLeads {get;set;}
        public Integer countOpenTasks {get;set;}
        public Integer countReps {get;set;}
        public Integer countOpenOpps {get;set;}
//        public Integer countExistingTasks {get;set;}
    } 
    
    //Public Property that will hold all the TableRows and PageBlockTable can use this Variable to get the whole List of rows
    public List<TableRow> rowList {get; set;}    

    //Constructor that runs a SOQL to get all the Records and build the List. This get executed automatically on the Page Load
    public matchedAccounts(){
            rowList = new List<TableRow>();
          TableRow tr;
        groupedResults = [SELECT Matched_Account__c, Count(Id) 
                          FROM Lead 
                          WHERE Matched_Account__c!=NULL 
                          AND IsConverted=FALSE GROUP BY Matched_Account__c];
        for (AggregateResult ar : groupedResults)  {
            acctLeadCountMap.put((Id)ar.get('Matched_Account__c'),(Integer)ar.get('expr0'));
        }
        system.debug('acctLeadCountMap '+acctLeadCountMap);
        
        List<AggregateResult> groupedProspects = new List<AggregateResult>([SELECT Matched_Account__c, Count(Id) 
                          FROM Lead 
                          WHERE Part_of_Prospecting_List__c=TRUE AND Matched_Account__c IN :acctLeadCountMap.keySet()
                          AND IsConverted=FALSE GROUP BY Matched_Account__c]);
        for (AggregateResult ar : groupedResults)  {
            prospLeadCountMap.put((Id)ar.get('Matched_Account__c'),(Integer)ar.get('expr0'));
        }
        
        List<Account> acctList = [SELECT OwnerId, Name, Domain_for_lead_conversion__c FROM Account WHERE Id = :acctLeadCountMap.keySet()];
        for (Account account : acctList) {
            if(acctRepCountMap.containsKey(account.Id)) {
                Set<Id> idSet = new Set<Id>(acctRepCountMap.get(account.Id));
                idSet.add(account.OwnerId);
                acctRepCountMap.put(account.Id, idSet);
            } else {
                acctRepCountMap.put(account.Id, new Set<Id>{account.OwnerId});
            }
            accountMap.put(account.Id, account);
        }
        system.debug('accountMap '+accountMap);
        
            //add matched lead owners to rep map
        List<Lead> matchedLeads = new List<Lead> ([SELECT Id,OwnerId,Matched_Account__c,Matched_Account__r.Id FROM Lead WHERE Matched_Account__c IN :acctLeadCountMap.keySet()]);
        for (Lead l :matchedLeads){
            if(acctRepCountMap.containsKey(l.Matched_Account__r.Id)) {
                Set<Id> idSet = new Set<Id>(acctRepCountMap.get(l.Matched_Account__r.Id));
                idSet.add(l.OwnerId);
                acctRepCountMap.put(l.Matched_Account__r.Id, idSet);
            } else {
                acctRepCountMap.put(l.Matched_Account__r.Id, new Set<Id>{l.OwnerId});
            }
        }

        //add contact owners to rep map
        List<Contact> conList = new List<Contact> ([SELECT Id,OwnerId,AccountId FROM Contact WHERE AccountId IN :acctLeadCountMap.keySet()]);
        for (Contact con :conList){
            if(acctRepCountMap.containsKey(con.AccountId)) {
                Set<Id> idSet = new Set<Id>(acctRepCountMap.get(con.AccountId));
                idSet.add(con.Account.OwnerId);
                acctRepCountMap.put(con.AccountId, idSet);
            } else {
                acctRepCountMap.put(con.AccountId, new Set<Id>{con.Account.OwnerId});
            }
        }

        //add opp owners to rep map
        List<Opportunity> oppList = new List<Opportunity> ([SELECT Id,OwnerId,AccountId FROM Opportunity WHERE AccountId IN :acctLeadCountMap.keySet()]);
        for (Opportunity opp: oppList){
            if(acctRepCountMap.containsKey(opp.AccountId)) {
                Set<Id> idSet = new Set<Id>(acctRepCountMap.get(opp.AccountId));
                idSet.add(opp.OwnerId);
                acctRepCountMap.put(opp.AccountId, idSet);
            } else {
                acctRepCountMap.put(opp.AccountId, new Set<Id>{opp.OwnerId});
            }
        }

        //add task owners to rep map - account
        List<Task> taskList = new List<Task> ([SELECT Id,WhoId,WhatId,OwnerId FROM Task WHERE WhatId IN :acctLeadCountMap.keySet()]);
        for (Task t: taskList){
            if(acctRepCountMap.containsKey(t.WhatId)) {
                Set<Id> idSet = new Set<Id>(acctRepCountMap.get(t.WhatId));
                idSet.add(t.OwnerId);
                acctRepCountMap.put(t.WhatId, idSet);
            } else {
                acctRepCountMap.put(t.WhatId, new Set<Id>{t.OwnerId});
            }
        }
/*
        //add task owners to rep map - contact
        List<Task> taskListA = new List<Task> ([SELECT Id,WhoId,WhatId,OwnerId FROM Task WHERE Who.AccountId IN :acctLeadCountMap.keySet()]);
        for (Task t: taskListA){
            if(acctRepCountMap.containsKey(t.WhatId)) {
                Set<Id> idSet = new Set<Id>(acctRepCountMap.get(t.WhatId));
                idSet.add(t.OwnerId);
                acctRepCountMap.put(t.WhatId, idSet);
            } else {
                acctRepCountMap.put(t.WhatId, new Set<Id>{t.OwnerId});
            }
        }

        //add task owners to rep map - lead
        List<Task> taskList = new List<Task> ([SELECT Id,WhoId,WhatId,OwnerId FROM Task WHERE Who.Matched_Account__c IN :acctLeadCountMap.keySet()]);
        for (Task t: taskList){
            if(acctRepCountMap.containsKey(t.WhatId)) {
                Set<Id> idSet = new Set<Id>(acctRepCountMap.get(t.WhatId));
                idSet.add(t.OwnerId);
                acctRepCountMap.put(t.WhatId, idSet);
            } else {
                acctRepCountMap.put(t.WhatId, new Set<Id>{t.OwnerId});
            }
        }
        */
        List<Account> accountList = [Select Id, 
                                        (Select Id From Contacts),                              
                                        (Select Id From Opportunities Where  Opportunity.StageName !='Duplicate Quote' AND IsClosed = false AND CloseDate >: todayDate), 
                                        (SELECT Id From Tasks WHERE Status!='Completed' AND ActivityDate>:todayDate AND 
                                                    (Type = 'Call/Email' OR Type = 'Call_Email' OR Type = 'Call:TT' OR Type = 'Call:LM' OR Type = 'Call:Demo' OR Type = 'Call:Other' OR Type = 'Follow_up' OR Type = 'Follow up')) 
                                    From Account Where Id IN :acctLeadCountMap.keySet()];
        for(Account acctRecord : accountList) {
            if(acctRecord.Contacts != null) acctContactCountMap.put(acctRecord.Id, acctRecord.Contacts.size());
            if(acctRecord.Opportunities != null) acctOpportunityCountMap.put(acctRecord.Id, acctRecord.Opportunities.size());
            if(acctRecord.Tasks != null) acctTaskCountMap.put(acctRecord.Id, acctRecord.Tasks.size());    
        }
        system.debug('acctContactCountMap '+acctContactCountMap);
        system.debug('acctOpportunityCountMap '+acctOpportunityCountMap);
        system.debug('acctTaskCountMap '+acctTaskCountMap);
        
        for(Id idAcct : acctLeadCountMap.keySet()){
            tr = new TableRow();
            tr.accName = accountMap.get(idAcct).Name;
            tr.domain = accountMap.get(idAcct).Domain_for_lead_conversion__c;
            tr.countLeads = acctLeadCountMap.get(idAcct);
            tr.countOpenOpps = acctOpportunityCountMap.get(idAcct);
            tr.countOpenTasks = acctTaskCountMap.get(idAcct);
            tr.countReps = acctRepCountMap.get(idAcct).size();
        
            /*Add the TableRow to the List here*/
            rowList.add(tr);
        }
    }
}