1

I am having trouble getting the current record Id paramater in a LWC and passing it to an Apex method. Am I missing something? How can this be done?

LWC wire method:

@wire(getOpportunityLineItems, {oppId: this.RecordId})
 contacts(result) {
     this.refreshTable = result;
     if (result.data) {
         this.data = result.data.map(row=>{
             return{...row, productName: row.Product2.Name}
         })
         this.error = undefined;


     } else if (result.error) {
         this.error = result.error;
         this.data = undefined;
     }

 }

Apex Method with SOQL

 @AuraEnabled(Cacheable = true)
public static List<OpportunityLineItem> getOpportunityLineItem(Id oppId){

    return [SELECT Id, Product2Id, Product2.Name, Name, Quantity, UnitPrice, ProductCode FROM OpportunityLineItem WHERE OpportunityId= :oppId];

}

1 Answer 1

3

If you're using the standard record Id API, it should be recordId, not RecordId (case-sensitive), and you should be using a reactive parameter:

@api recordId;
@wire(getOpportunityLineItems, {oppId: '$recordId'})
1
  • This worked thanks!
    – Jordan
    Nov 19, 2019 at 17:05

You must log in to answer this question.

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