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;

    }
}

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
    ];

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.