2

Apex methods that are to be cached must be marked as @AuraEnabled(cacheable=true) client side

  @wire(updateLots,{victim : '$payedLots'})
updateLots(data, error) {
    console.log('inside payed');
    if(data) {
        console.log(data);
    }
    if(error) {
        console.log(JSON.stringify(error));
    }
}

and server side

  @AuraEnabled
public static string updateLots(List<String> victim) {
    try {
        List<Lot__c> lotList = [select id from Lot__c where id in :victim];
        for(Lot__c  lot : lotList) {
            lot.payed__c = true;
        }
        update lotList;
    }
    catch(DmlException e) {
        return e.getMessage();
    }
    return 'Success';
}

Can anyone tells me what do I do wrong?

4

You cannot use a wire to invoke a non-cacheable aura enabled function. In addition, a cacheable one cannot perform DML operations.

You need to convert the client to use imperative invocation of this DML-based aura enabled function.

Check out the documentation for details.

| improve this answer | |
  • By what way can pass parameters? – pincet Dec 20 '19 at 11:09
  • Visit the documentation page I linked to and search for "apexImperativeMethodWithParams". This will lead you to where you can find the details. – Phil W Dec 20 '19 at 11:16

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.