+ Start a Discussion
ManjusrinuManjusrinu 

I need to get product price from quote

Hi All,

I am iterating quote records ,

Now when the first quote record comes into loops ,i should get the associated prdouct price  which is linked to oppournity 

Can anyone help me how to query ?..

for(Quote eachQuote : oppournityQuotes) {
            if(eachQuote.Account.BillingState == 'Telangana'  && eachQuote.Oppournity.product2.listprice  ) {
}   

AnudeepAnudeep (Salesforce Developers) 
Hi Manju, 

You need to grab the opportunity Ids from the for loop and run a SOQL outside of your for loop to get the required information. I am posting here a sample code and highlighting the said part 
 
trigger CreateQLI on CQuote__c (after insert,after update) {
    Set<Id> opportunityIds = new Set<Id>();
    List<CQuote__c>quotelist=new List<CQuote__c>();
    for(CQuote__c q : Trigger.new)
    {
        if(q.QOpp_Name__c != NULL)
        {
            opportunityIds.add(q.QOpp_Name__c);
            quotelist.add(q);
        }
    }
    Map<Id, COpportunity__c> oppsWithLineItems = new Map<Id, COpportunity__c>([SELECT Id,(select id,CurrencyIsoCode,Opportunity__c,Principal_Name__c, Product_Category__c,Product_Description__c,
                        Product__r.name,Quantity__c,Unit_Price__c from Opportunity_LineItems__r)from COpportunity__c WHERE Id IN :opportunityIds]);

    if(opportunityIds.size() > 0)
    {
        // Loop through Quotes
        List<Quote_Line_Item__c > quoteItemsForInsert = new List<Quote_Line_Item__c >();
        for(CQuote__c o : quotelist)
        {
            // For each Quote get the related opportunity and line items, loop through the line items and add a new quote line item to the quote line item list for each matching opportunity line item
            COpportunity__c oppWithLineItem = oppsWithLineItems.get(o.QOpp_Name__c);
            for(Opportunity_LineItem__c oli : oppWithLineItem.Opportunity_LineItems__r)
            {
                quoteItemsForInsert.add(new Quote_Line_Item__c(
                        Quote_Name__c=o.id,
                        Product_Name__c=oli.Product__r.name,
                        Principal_Name__c=oli.Principal_Name__c,
                        Product_Category__c=oli.Product_Category__c,
                        CurrencyIsoCode=oli.CurrencyIsoCode,
                        Unit_Price__c=oli.Unit_Price__c
                ));
            }
        }
        // If we have order line items, insert data
        if(quoteItemsForInsert.size() > 0)
        {
            insert quoteItemsForInsert;
        }
    }


    
}

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you