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

}
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'})
| improve this answer | |
  • This worked thanks! – Jemat Nov 19 '19 at 17:05

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.