“Error messages are like cryptic puzzles – challenging us to decipher their hidden meanings, that can range from the frustratingly vague to the downright bizarre, leaving us scratching our heads and wondering if our computers have developed a sense of humor.“
Internal Salesforce.com Error – This is not an interesting error message with sufficient details. One of the popular errors troubled many developers working on lwc components/Aura components after the salesforce Winter 20 release enforced update.
This critical update changed the behavior of @AuraEnabled
Apex controllers that don’t specify with sharing
or without sharing
to default to with sharing
. This critical update applies only to orgs created after Spring ’18 or orgs that activated the retired “Use without sharing
for @AuraEnabled
Apex Controllers with Implicit Sharing” critical update that had the opposite effect and set the default to without sharing
.
This change applies to Aura and Lightning web components in Lightning Experience, Salesforce Classic, Lightning communities, and all versions of the Salesforce app.
This behavior made Apex controllers consistent in Aura components and Visualforce pages. With this update with sharing
defaulted on Apex classes used by Aura components or Lightning web components.
How is it impacting the existing LWC/aura components?
Even though its secured the access to @AuraEnabled apex classes – whereever the SOQL queries working perfectly prior to this started throwing FATAL_ERROR Internal Salesforce.com Error .
For example the below query in an
Apex class started
failing with a fatal error.
SELECT Id,NPI__c,FirstName,Lastname,Phone,AccountId,Account.Name FROM Contact WHERE (Lastname LIKE ‘%Jackson%’) AND RecordType.DeveloperName = ‘Medical_Staff’ ORDER BY FirstName,MiddleName,LastName,Id LIMIT 100
How do I fix the blocking error?
The Apex class that was called by the LWC did not have an explicit sharing clause. Which implies, because of the critical update, “with sharing”. That means that users got an error, because they do not have access to the Contact object, which is private.
It can be solved by setting the sharing clause of the class called by the LWC to “without sharing”. It is appropriate in this case.
Though this is a very simple update, it made developers do a lot of debugging back and forth using debug logs, query analysis, and data analysis where there was no clue why all of a sudden it stopped working, so sharing this thinking may be helpful!