+ Start a Discussion
Suresh RaghuramSuresh Raghuram 

Adding different fields from three different objects in a wrapper class

Hi Comminity,

I have a requirement where i had to show different fields from 3 different objects into a single pageblock table with checkbox select option. so I am using a wrapper class. My code is below. Can any correct me where I am making the mistake.

public List<AccountTeamWrapper> getAgreementList(){
        if(AgreementList == null){
            agreementList = new List<AccountTeamWrapper>();
           for(Agreement__c agr:[select Id, name, Administrative_Source_System__c from Agreement__c where Customer__c=: accountId]){
                agreementList.add(new AccountTeamWrapper(agr, null));           
List<Agreement_Rep__c> aggRepList = [select Id, Name, Agreement__r.Id, Agreement__r.Name, Agreement__r.Administrative_Source_System__c, REP_AGRMT_BEGIN_DT__c,  REP_AGRMT_END_DT__c
                                                    from Agreement_Rep__c where Agreement__r.Customer__c =: accountId];
            system.debug('************* Agreement size:'+aggRepList.size());
            system.debug('************* Agreement :'+aggRepList);                                                   
            for(Agreement_Rep__c aggRep: aggRepList){
                agreementList.add(new AccountTeamWrapper(null, aggRep));
return agreementList;
        return null;
public class AccountTeamWrapper{       
        public Agreement__c agreement{get;set;}
        public Agreement_Rep__c agreementRep{get;set;}       
        public Boolean selected{get;set;}       
        public AccountTeamWrapper(Agreement__c agr, Agreement_Rep__c aggRep){
            agreement = agr;
            agreementRep = aggRep;
            selected = false;
Hi Suree,
it seems like you are trying to use/populate the wrapper class in the same way that you would a Map collection.  I have an idea on how to fix this, but I was wondering if there is a relationship between the Agreement__c and Agreement_Rep__c records that are in a single AccountTeamWrapper record? 
Suresh RaghuramSuresh Raghuram
Yes they do have.
Anand Jeevakan 5Anand Jeevakan 5
Hi Suree,
Were you able to resolve this. Could you please post the code if you have done this. I have a similar requirement.

Thank you