0

Query String

[SELECT BillingCountry, Industry, (SELECT Id, Name,Amount , StageName FROM Opportunities) FROM Account WHERE BillingCountry = 'USA']

Data Output

enter image description here

Now how i display those data on datatable ?

So far i tried

<apex:pageBlockTable value="{!lstResultWrapper}" var="items" id="table">
                <apex:column headerValue="Industry"> 
                <apex:outputText value="{!items['industry']}"/> 
                </apex:column> 
                <apex:column headerValue="Name"> 
                <apex:outputText value=""/> 
                </apex:column> 
   </apex:pageBlockTable>

But i did not understanding how i get the data which is coming from opportunity table Thanks in advance

2

I think there are 2 ways you can do this:

1) Create nested tables like:

<apex:page tabstyle="Account" controller="nestedqueryexample">
    <apex:pageblock> 
        <apex:pageblocktable value="{!accsandtmember}"  var="accdet">
            <apex:column >
                   <apex:facet name="header">                                        
                         Team Members                                                                               
                    </apex:facet>
                    <apex:pageblocktable value="{!accdet.AccountTeamMembers}" var="tm">
                        <apex:column headerValue="Team Member">
                               <apex:outputfield value="{!tm.User.Name}"/>
                         </apex:column>
                         <apex:column headerValue="Role">
                               <apex:outputfield value="{!tm.TeamMemberRole}"/>
                         </apex:column>                          
                    </apex:pageblocktable>
            </apex:column>
            <apex:column headervalue="Account Name">
                    <apex:outputtext value="{!accdet.Name}"/>
            </apex:column>
            <apex:column headervalue="Billing Country">
                    <apex:outputtext value="{!accdet.BillingCountry}"/>
            </apex:column>
        </apex:pageblocktable>
    </apex:pageblock>
</apex:page>  

Where class is like:

public class nestedqueryexample
{
  public List<Account> getaccsandtmember()
  {
      List<Account> accounts = [Select Id,(Select TeamMemberRole, User.Name From Account.AccountTeamMembers), Name, BillingCountry from Account];
      return accounts;
  }
}

Important thing to note is how value="{!accdet.AccountTeamMembers}" var="tm" is used to loop over the nested records Out put

2) Second option is to create wrapper class that have all the field from child and parent object. Store your data into list of objects of wrapper class. And then use it in your table.

for ex: take a look at this http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/

Here we have wrapper class that holds 2 things 1 account object 2 Boolean status

In your wrapper class you can hold both objects.

  • @AtulRajgure9 can you expalin the secound option pls – moin khan Mar 11 '16 at 8:32
  • see m updated answer – AtulRajguru9 Mar 12 '16 at 3:57

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.