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
csathishbabucsathishbabu 

How to get RelatedList Values in Opportunity Tab to Visual Force Page

Hi I have created a visual Force page for Create a invoice for the Products added in The Relatedlist of opportunity Tab,

as im new to apex COntroller,I want to know how to retrive the products in the related list of opportunity tab to a visualforce page Suggest me an idea to achieve it ur help will be of great help Thanks.

_Prasu__Prasu_

Which controller your using? Standard controller or custom controller?

csathishbabucsathishbabu

Custom Controller

_Prasu__Prasu_

you can make query:

 

OpportunityLineItem[] products =  [Select o.Quantity, o.UnitPrice,o.ListPrice,o.Id,o.OpportunityId,o.Description,o.Description__c, o.Opportunity.Description, o.Opportunity.Id, o.Opportunity.Name, o.Opportunity.StageName,o.PricebookEntry.Id,o.PricebookEntryId, o.PricebookEntry.Name,o.PricebookEntry.Product2Id from OpportunityLineItem o where o.OpportunityId =: opportunityId ];

 

OpportuniyId should be a variable containing valid opportunity id.

csathishbabucsathishbabu

Thanks Dude, i got the product list in visualpage but now i want to calculate the total amount of all the products listed in visualpage so how to loop the products and sum in controller

b-Forceb-Force

FIrst Add o.Quantity in SOQL

 

Looping

 

 

Double oppTotal=0;
for(OpportunityLineItem ol : products)
{
OppTotal=ol.UnitPrice * ol.Quantity;
}

 

 

OppTotal will give you product total

 

Thanks,

Bala