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

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:

Leave a Reply