0

I encountered an issue, as I want to access a property of an object I'm passing from a lwc to an apex method, like this:

valuesObj.ml_id = this.sfItem.id;
this.itemObj = valuesObj;

and then:

processItemEdit( {item : this.itemObj} ).then(r => {
     console.log('r', r);
});

This is the apex method:

@AuraEnabled
public static void processItemEdit(CsvItem item){
    List<CsvItem> items = new List<CsvItem>();
    String seller_id = String.valueOf(item.ml_id);
    Seller_Setting__c setting = SellerSettingDataManager.getSetting(seller_id);
    setting = BatchApexListItems.getSetting(setting.id);
    items.add(item);
    BatchApexListItems.processItemsCsv(items, setting);
}

For some reason, apex throws an error when I try to deploy, saying the variable 'item.ml_id' does not exist, when it is defined in the first line of code I included here. What is going on?

3
  • 1
    Can you share CsvItem apex class also? Feb 10 '21 at 17:01
  • 1
    oohh I understand the problem. If that class doesn't have that property, apex won't find it. The object I created in the component does have the property but when converted to CsvItem, it doesn' translate, right? Feb 10 '21 at 17:23
  • Yes. You have got it right.
    – Naga
    Feb 10 '21 at 21:40
0

As I see you have just created the object CsvItem on the client side. But when the object is passed to server side, i.e. Apex, you need same properties in Apex class defined as 'CsvItem'

For eg:

public class CsvItem{

    public String ml_id {get ; set; }
}
1
  • that was the problem. Anyway, I solved it by passing the right properties directly from the lwc. thanks for the help Feb 11 '21 at 15:51

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.