0

I am new to APEX/SOQL and am trying to get only quote line items for the current record. Right now I have hard coded the quoteId but would like this to be a variable based on current record. How would I accomplish this?


public with sharing class QuoteLineItems {


    @AuraEnabled(cacheable=true)
    public static List<QuoteLineItem> getQuoteLineItems() {
        List<QuoteLineItem> QuoteLineItems =
               [SELECT Id, Product2.Name, Product2.ProductCode, Quantity, Discount_reason__c, Minimum_Price__c, ListPrice, UnitPrice, Quote.LineItemCount FROM QuoteLineItem WHERE QuoteId ='0Q02o000003qLO8CAM'];


        return QuoteLineItems;

    }
}

1 Answer 1

4

You need to pass in the Id as a parameter. Then in your query, use bind syntax (:).

@AuraEnabled(cacheable=true)
public static List<QuoteLineItem> getQuoteLineItems(Id quoteId) {
    return [
        SELECT
            Product2.Name, Product2.ProductCode, Quantity,
            Discount_reason__c, Minimum_Price__c,
            ListPrice, UnitPrice, Quote.LineItemCount
        FROM QuoteLineItem WHERE QuoteId = :quoteId
    ];

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .