3

I had an apex method with @AuraEnabled(cacheable=true) and a wire method in LWC, all was working fine.

Then to meet the new requirement I was experimenting with @AuraEnabled(cacheable=false). With this config the LWC refused to run the apex method with this error:

{
    "status": 500,
    "body": {
        "message": "Apex methods that are to be cached must be marked as @AuraEnabled(cacheable=true)"
    },
    "headers": {}
}

I set it back to (cacheable=true) but the 500 error is still appearing, I tried hard refresh, closing the browser but it doesn't not help.

What can I do to get the original behaviour back?

4
  • 1
    go to setup -> session settings and remove persistence caching
    – ytiq
    Commented May 25, 2022 at 12:17
  • 1
    Double check that you really did manage to reset the cacheable directive in your apex and either logout from the org entirely then sign in again (may reset the cache) or use session settings as @ytiq said, to turn off caching.
    – Phil W
    Commented May 25, 2022 at 12:19
  • 2
    BTW, wires require cacheable methods. You would have to switch to imperative invocation to use a non-cacheable method. This is covered in the documentation.
    – Phil W
    Commented May 25, 2022 at 12:21
  • After setting it back to (cacheable=true) you are getting the same error. Try 'Empty cache and Hard reload' it should work.
    – Rachit
    Commented May 10 at 5:53

4 Answers 4

3

I had the same issue and had everything correct but was still getting the same error.

I had to change the Apex method name and use the new Apex method's name in the .js file. Salesforce is weird sometimes... -_-

3

I managed to resolve this issue by simply redeploying the lwc component that calls the Apex method

1

Apex method with @AuraEnabled(cacheable=true) and a wire method in LWC is actually fine.

Because wire adaptor use browser cache to store the record data coming from @wire. By default @AuraEnabled is @AuraEnabled(cacheable=false) which means the server side method (apex method) can't be called by wire adaptor, therefore LWC refused to run the apex method with this error.

But imperative call to the apex method is possible without @AuraEnabled(cacheable=true).

Imperative call doesn't use browser cache to store received data.

1

@wire cannot call @AuraEnabled(cacheable=false).

You might need to modify your LWC component using imperative call.

From Salesforce Documentation Wire Apex Method to Component

Remember that the method must be static, and global or public. The method must be decorated with @AuraEnabled(cacheable=true)

You must log in to answer this question.

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