How to get Product Name from Opportunity Line item in SOQL?

Sample Query:

SELECT PricebookEntry.Product2.Name FROM OpportunityLineItem

(Or)

SELECT PricebookEntry.Name FROM OpportunityLineItem LIMIT 10 

Sample Code:

for ( OpportunityLineItem OLI : [ SELECT PricebookEntry.Product2.Name, PricebookEntry.Name FROM OpportunityLineItem LIMIT 10 ] ) {
    
    system.debug( OLI.PricebookEntry.Product2.Name );
    system.debug( OLI.PricebookEntry.Name );
    

}

Output:


1 comment:

  1. Try this - SELECT ProductCode__c, PricebookEntry.Name FROM OpportunityLineItem

    ReplyDelete