1

How many sObjects can we query in Wrapper-Class list?

for example: I have 3 Objects(2 Custom Objects and 1 Standard Object), Can we hold these records in Wrapper Class and use the Wrapper list in PageBlock Table?

Please suggest.

Below is my controller,

public with sharing class Product_on_account {

// Variable Declaration
Account act;
Public Financial__c[] fafetch {get;set;}
Public Opportunity[] opfetch {get;set;}
Public Call__c[] cafetch {get;set;}
public List<MyWrapper> listwrap {get; set;}

//Controller
public Product_on_account (ApexPages.StandardController stdController)
{
    // Account record
    this.act = (Account)stdController.getRecord();

    // Financial Account Fetch
    fafetch = [select Id, Name, AccountId__c,Profitability_Period__c, Profitability_Type__c, Account_Number__c, Foreign_Exchange__c,KMS__c, Payables_Products__c, 
               Deposit_Revenue__c, Credit_Revenue__c, Syndication_Fees__c, Equity_Capital_Market__c, Debt_Capital_Market__c, Mortgage_Banking__c, Receiveable_Products__c,
               Derivatives__c, Cash_Management_Total__c, Liquidity_Products__c, Info_Srvc_Products__c, Financial_Advisory__c, Other__c, Commercial_Card__c, Prepaid__c,
               Healthcare__c, Other_Products__c from Financial__c where AccountId__c =: act.ID and Profitability_Period__c =: 'T12' and Profitability_Type__c =: 'Customer'];

    // Opportunity Fetch
    opfetch = [select id, name, AccountId, Product_Category__c, RecordType.Name from opportunity where AccountID =: act.ID];
    system.debug(opfetch.size());

    //Call Fetch
    cafetch = [Select id, name, AccountId__c, Product__c,RecordType.Name, Product_Category__c,Product_Family__c from call__c where RecordType.Name =: 'Account Call' and AccountId__c =: act.ID];


        listwrap = new List<MyWrapper>();
        if(fafetch.size() <> 0){
        for(Financial__c m : fafetch){
        MyWrapper mr = new MyWrapper(m);
        listwrap.add(mr);        
        }
        }
        system.debug(listwrap);

        listwrap = new List<MyWrapper>();
        if(opfetch.size() <> 0){
        for(Opportunity o : opfetch){
        MyWrapper mr = new MyWrapper(o);
        listwrap.add(mr);        
        }
        }
        system.debug(listwrap);

        listwrap = new List<MyWrapper>();
        if(cafetch.size() <> 0){
        for(Call__c c : cafetch){
        MyWrapper mr = new MyWrapper(c);
        listwrap.add(mr);        
        }
        }
        system.debug(listwrap);

}   


public class MyWrapper
{
    Public Financial__c fas {get;set;}
    Public Opportunity opp {get;set;}
    Public Call__c clls {get;set;} 

    public MyWrapper(Opportunity o)
    {
        this.opp = o;
        system.debug(opp);
    }


    public MyWrapper( Financial__c m)
    {
       this.fas = m; 
       system.debug(fas);
    } 

    public MyWrapper( Call__c c)
    {
       this.clls = c; 
       system.debug(clls); 
    } 

}

}

is this correct? its saving with no error. but when I use this list in PageBlockTable in VF page, for 2 objects its working fine. but for the 3rd the value is not available.

Thanks.

Added my VF page (PageBlockTable) as well. Here am trying to display the image if my conditions mets.

<apex:form style="width:1550px">
    <apex:pageBlock >

    <apex:pageBlockSection >
    <apex:PageBlockTable value="{!listwrap}" var="s" style="width:100%" rows="1" >

      <apex:column headerValue="Object Name" >
        <apex:outputLabel value="Financials" /><br/><br/>
        <apex:outputLabel value="Opportunity" /><br/><br/>
        <apex:outputLabel value="Call"/>
      </apex:column>

      <apex:column headerValue="Debit">
        <apex:image value="{!If(s.fas.Deposit_Revenue__c == null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Credit">   
        <apex:image value="{!If(s.fas.Credit_Revenue__c <> null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/> <br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Credit', $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Syndication">   
        <apex:image value="{!If(s.fas.Syndication_Fees__c !=  null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'XXX' && s.opp.Product_Category__c == 'Financial Advisory', $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>            
      </apex:column>

      <apex:column headerValue="Equity">
        <apex:image value="{!If(s.fas.Equity_Capital_Market__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/> <br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Invst Bnkg & Market' && s.opp.Product_Category__c == 'Insti Equity', $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column> 

      <apex:column headerValue="Debt">
        <apex:image value="{!If(s.fas.Debt_Capital_Market__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Invst Bnkg & Market' && s.opp.Product_Category__c == 'Debt', $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column> 

      <apex:column headerValue="Financial Advisory">
        <apex:image value="{!If(s.fas.Financial_Advisory__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Invst Bnkg & Market' && s.opp.Product_Category__c == 'Financial Advisory', $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column> 

      <apex:column headerValue="Other">
        <apex:image value="{!If(s.fas.Other__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/> <br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'XXX' && s.opp.Product_Category__c == 'Derivatives', $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column> 

      <apex:column headerValue="Derivatives">
        <apex:image value="{!If(s.fas.Derivatives__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Invst Bnkg & Market' && s.opp.Product_Category__c == 'Derivatives', $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Foreign Exchange">
        <apex:image value="{!If(s.fas.Foreign_Exchange__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="KMS">
        <apex:image value="{!If(s.fas.KMS__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Purchase Cards">
        <apex:image value="{!If(s.fas.Commercial_Card__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Payables">
        <apex:image value="{!If(s.fas.Liquidity_Products__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="CIS">
        <apex:image value="{!If(s.fas.Receiveable_Products__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/> <br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Account Services">
        <apex:image value="{!If(s.fas.Payables_Products__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/> <br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column> 

      <apex:column headerValue="Receivable">
        <apex:image value="{!If(s.fas.Info_Srvc_Products__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Healthcare Solutions">
        <apex:image value="{!If(s.fas.Healthcare__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/> <br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Prepaid Cards">
        <apex:image value="{!If(s.fas.Prepaid__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/> <br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'Deposit & ECP' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Other Products">
        <apex:image value="{!If(s.fas.Other_Products__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/> <br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'XXX' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

      <apex:column headerValue="Cash Management">
        <apex:image value="{!If(s.fas.Cash_Management_Total__c != null, $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/> <br/><br/>
        <apex:image value="{!If(s.opp.RecordType.Name == 'XXX' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/><br/><br/>
        <apex:image value="{!If(s.clls.Product_Family__c == 'Credit' , $Resource.Green_Indicator_for_Product,$Resource.White_space_for_Product)}" width="30" height="30"/>
      </apex:column>

  </apex:PageBlockTable>      
  </apex:pageBlockSection>      
  </apex:pageblock>

</apex:form> 

  • 1
    I don't aware about a limitation there, as long as memory allocation doesn't get hit. You can have any type of variables and bind them with front end – highfive Jul 26 '16 at 10:09
  • Thanks for the quick response. find my controller pasted this gives only 2 sObjects in pageBlockTable on VF page. – sun86 Jul 26 '16 at 10:28
  • add your pageblock table code as well – highfive Jul 26 '16 at 10:36
  • Added my pageblockTable (VF page). – sun86 Jul 26 '16 at 10:40
1

You can use any number of object in wrapper class. there is no limitation

  • Thanks Ratan for the quick response. find my controller pasted this gives only 2 sObjects in pageBlockTable on VF page. – sun86 Jul 26 '16 at 10:27
  • @sun86 are you sure. in your org you have correct data for Call__c ? put debug logs and check if Call__c records added into wrapper list or not. – Ratan Paul Jul 26 '16 at 10:30
  • Yes I have. pasted you the debug values as well. ///// 16:03:35.0 (77423605)|USER_DEBUG|[82]|DEBUG|Call__c:{Id=a0621000000NWX0AAO, Name=Call-145444, AccountId__c=00121000002jgWxAAI, RecordTypeId=012o0000000OBtEAAW, Product_Family__c=Deposits & ECP} 16:03:35.0 (77544077)|USER_DEBUG|[82]|DEBUG|Call__c:{Id=a0621000000NXttAAG, Name=Call-145447, AccountId__c=00121000002jgWxAAI, RecordTypeId=012o0000000OBtEAAW, Product_Family__c=Credit} – sun86 Jul 26 '16 at 10:35
1

Problem is in your controller it seems. Before every for loop you are resetting the wrapper list by adding the statement listwrap = new List<MyWrapper>();. You have to do it only once just for the initializing the list. Afterwards only add the elements. Otherwise only lastly added items will be remain there.

Below is your constructor after refactoring. Note the removal off listwrap = new List<MyWrapper>(); after first initialization.

public Product_on_account (ApexPages.StandardController stdController)
{
    // Account record
    this.act = (Account)stdController.getRecord();

    // Financial Account Fetch
    fafetch = [select Id, Name, AccountId__c,Profitability_Period__c, Profitability_Type__c, Account_Number__c, Foreign_Exchange__c,KMS__c, Payables_Products__c, 
               Deposit_Revenue__c, Credit_Revenue__c, Syndication_Fees__c, Equity_Capital_Market__c, Debt_Capital_Market__c, Mortgage_Banking__c, Receiveable_Products__c,
               Derivatives__c, Cash_Management_Total__c, Liquidity_Products__c, Info_Srvc_Products__c, Financial_Advisory__c, Other__c, Commercial_Card__c, Prepaid__c,
               Healthcare__c, Other_Products__c from Financial__c where AccountId__c =: act.ID and Profitability_Period__c =: 'T12' and Profitability_Type__c =: 'Customer'];

    // Opportunity Fetch
    opfetch = [select id, name, AccountId, Product_Category__c, RecordType.Name from opportunity where AccountID =: act.ID];
    system.debug(opfetch.size());

    //Call Fetch
    cafetch = [Select id, name, AccountId__c, Product__c,RecordType.Name, Product_Category__c,Product_Family__c from call__c where RecordType.Name =: 'Account Call' and AccountId__c =: act.ID];


        listwrap = new List<MyWrapper>();   // this is for initializing the list
        if(fafetch.size() <> 0){
            for(Financial__c m : fafetch){
                MyWrapper mr = new MyWrapper(m);
                listwrap.add(mr);        
            }
        }
        system.debug(listwrap);

        if(opfetch.size() <> 0){
            for(Opportunity o : opfetch){
                MyWrapper mr = new MyWrapper(o);
                listwrap.add(mr);        
            }
        }
        system.debug(listwrap);

        if(cafetch.size() <> 0){
            for(Call__c c : cafetch){
                MyWrapper mr = new MyWrapper(c);
                listwrap.add(mr);        
            }
        }
        system.debug(listwrap);

}
  • thanks for your response. still there is no values in opportunity & Call__c object records from LIST- listwrap in VF page mentioned in pageBlockTable. – sun86 Jul 27 '16 at 5:23
  • Just noticed that you have specified attribute rows="1" in your pageBlockTable. Remove that so all the returned list get rendered. – highfive Jul 27 '16 at 6:20
  • @highfive-Yes, I removed that attribute rows="1" in PageblockTable and the other 2 table values are present. but now it shows 3 tables on VF page. can you please help on this?. Thank you so much for your help. – sun86 Jul 27 '16 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.