Development questions
Why must an Apex method be cacheable=true to be used with @wire, and what are the restrictions?
DevelopmentMedium
@wire may call the method many times (reactive re-provisioning), so Salesforce requires it to be side-effect free and caches the result on the client.
Restrictions of @AuraEnabled(cacheable=true):
- No DML operations (insert, update, delete) in the method.
- Results are cached, so data may be stale until
refreshApexor a cache refresh.
If you need DML: call the Apex method imperatively without cacheable=true. If data may be stale after a DML, call refreshApex(this.wiredResult) where wiredResult is the stored wire response.
lwcapexcacheable
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?