Sample Code Without Sharing: Give Guest Users Access to Create and Read Records in the Same Transaction
In this collection of code samples, the guest user enters details to report a support issue and Apex code creates a case. An Apex method retrieves the new record and Aura components display parts of the record to the guest user after creation. The Apex code runs without sharing because we aren’t relying on object permissions and platform sharing to allow the guest user to access the record.
This sample Aura component displays several components where the user enters details about the case. After creation, the lightning:card component displays the new case’s case number and status.
This sample JavaScript controller processes events for the Aura component and calls the methods in the helper file.
This JavaScript helper creates an asynchronous request to create a case with the submitted data. When the request completes, the callback stores the case number and case status in variables used by the Aura component.
This sample Apex controller creates the record, retrieves the new record, and returns the required fields from the new record to the client. Because object permissions and platform sharing aren’t used, this controller runs without sharing.
To avoid unintended exposure of record data, the CreateCase method returns only the CaseNumber and Status fields.
Any system or individual on the internet can invoke @AuraEnabled classes. Make sure that the method returns only the required fields from the new record.
See Also