A Salesforce Sites or Experience Cloud Guest User runs Apex that performs a standard DML insert on a record containing a lookup (cross-reference) to another object. The insert throws INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, even though it's expected that the without sharing class allow it.
Symptoms
INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY is thrown on the insert line.without sharing.Applies To
Root Cause
without sharing controls record-level sharing only. Per the Apex Developer Guide, sharing declarations do not enforce object-level access or field-level security. So declaring a class without sharing tells Apex to ignore sharing rules — it does not ignore the running user’s CRUD or FLS permissions.
means the insert or update references a record that either does not exist or is not accessible to the running user — the parent record pointed to by a lookup — not necessarily the record being inserted. Salesforce’s error reference notes that even when the profile grants Read, Create, and Edit access, the cause can still be record ownership and sharing on that referenced record.
INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY
For a Guest User, the DML runs in the restricted Guest User context: the referenced parent record is frequently not visible under the Guest User sharing/visibility model, and (in API version 67.0 and later, where DML runs in user mode by default) the Guest User’s object and field permissions are enforced as well. Because without sharing changes only sharing — not object/field access — it does not, by itself, resolve the error.
Choose the approach that fits your security model. Option A is the direct code fix; Options B and C follow Salesforce’s official Guest User guidance.
Use this when the Guest User legitimately needs to create the record but should not be granted broad standing access to the referenced object.
Open the Apex class that performs the insert.
Confirm the class is saved on an API version where the Database method AccessLevel overloads are available (see the version note below).
Replace the plain DML statement:
insert obj;
with an explicit system-mode call that includes the required allOrNone argument:
Database.SaveResult sr = Database.insert(obj, true, AccessLevel.SYSTEM_MODE);
AccessLevel.SYSTEM_MODE runs that single DML operation in system mode, so object permissions and field-level security are not enforced for it, allowing the insert to succeed for the Guest User. (In system mode, record sharing for the operation is governed by the class’s with/without sharing keyword.)
Add input validation and business-logic checks in the class so a Guest User can only insert the record they are meant to create. System mode removes permission enforcement for that operation, so the class itself must constrain what is written.
Verify: Save the class, then reproduce the original flow as a Guest User and confirm the record is created without INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY. Inspect sr.isSuccess() (and sr.getErrors() on failure) to confirm the outcome.
Per Salesforce guidance, without sharing for Guest Users should be scoped tightly — only to create or update the record the Guest User just created, never other records — with additional safeguards (for example, encrypted record-ID checks) if the record is accessed again later.
005459387

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.