You need to sign in to do that
Don't have an account?
Rishiraj Singh 17
How do I find the count of products associated to an opportunity using the Apex code in Salesforce?
I am working for a client request to develop a Opportunity Summary Page(Visualforce page), for which I need to show below recordds for the number of opportunities:
Opportunity NameAccount NameProducts NameAmountQuantitySubTotalNumber of ProductsTotal Payable AmountStageApproval History
Opportunity NameAccount NameProducts NameAmountQuantitySubTotalNumber of ProductsTotal Payable AmountStageApproval History
use below code :
apex : output:
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others forums best practice (https://developer.salesforce.com/forums/ForumsMain?id=9060G000000MVrtQAG)
thanks
sfdcmonkey.com
All Answers
<apex:page standardController="Opportunity" recordSetVar="opportunity" extensions="OppExtension">
<apex:form >
<apex:pageBlock >
<apex:pageblockSection title="Opportunities Summary Details" collapsible="true" Columns="10">
<apex:pageBlockTable value="{!opportunity}" var="opp">
<apex:column value="{!opp.Name}"/>
<apex:column value="{!opp.Account.name}"/>
<apex:column headerValue="Product Details">
<apex:pageBlockTable value="{!opp.opportunityLineItems}" var="opplt">
<apex:column value="{!opplt.Product2.Name}"/>
<apex:column value="{!opplt.ListPrice}"/>
<apex:column value="{!opplt.Quantity}"/>
<apex:column value="{!opplt.TotalPrice}"/>
</apex:pageBlockTable>
</apex:column>
<apex:column headerValue="Number Of Products">
<apex:outputText value="{!productSize}"></apex:outputText>
</apex:column>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public with sharing class OppExtension {
private Opportunity oppt;
public Integer productSize{get; set;}
public OppExtension(ApexPages.StandardSetController controller) {
this.oppt = (Opportunity)Controller.getRecord();
productSize =[select count() from PricebookEntry where Id IN (Select PricebookentryId from opportunityLineItem where opportunityId=:oppt.id)];
}
}
But everytime Count() appears as 0... Please help!
use below code :
apex : output:
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others forums best practice (https://developer.salesforce.com/forums/ForumsMain?id=9060G000000MVrtQAG)
thanks
sfdcmonkey.com