function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepak agarwal 9Deepak agarwal 9 

Apex class for accounts

apex class to get each Account and their opportunities count.
Best Answer chosen by Deepak agarwal 9
Magesh Mani YadavMagesh Mani Yadav
Hi Deepak,

Here is the class and VF page that should work for you.

Controller
public class testClasss {
    public List<Account> accs {get { return [select id, name, (select id from Opportunities) from Account];}set;}    
}

VF
 
<apex:page controller="testClasss" >
    <apex:pageBlock>
   <apex:pageblockTable value="{!accs}" var="acc">
   <apex:column value="{!acc.name}"/>
   <apex:column value="{!acc.Opportunities.size}"/>
   </apex:pageblockTable>
    </apex:pageBlock>
</apex:page>

 

All Answers

Magesh Mani YadavMagesh Mani Yadav
Hi Deepak,

Here is the class and VF page that should work for you.

Controller
public class testClasss {
    public List<Account> accs {get { return [select id, name, (select id from Opportunities) from Account];}set;}    
}

VF
 
<apex:page controller="testClasss" >
    <apex:pageBlock>
   <apex:pageblockTable value="{!accs}" var="acc">
   <apex:column value="{!acc.name}"/>
   <apex:column value="{!acc.Opportunities.size}"/>
   </apex:pageblockTable>
    </apex:pageBlock>
</apex:page>

 
This was selected as the best answer
Deepak agarwal 9Deepak agarwal 9
Thanks  Very much Magesh