Loading
Slack 관련 문의처가 Salesforce Help로 통합 및 변경됩니다.더 많이 읽기

Guest User Insert Fails with Cross-Reference Access Error

게시 일자: Sep 9, 2026
상세 설명

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

  • The error INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY is thrown on the insert line.
  • The Apex class is explicitly declared without sharing.
  • The Guest User permission set or profile appears to grant access to the objects involved.
  • The record being inserted references another record through a lookup or master-detail field.

Applies To

  • Salesforce Sites and Experience Cloud sites that run Apex in the Guest User context.
  • Apex classes performing DML on records with a lookup/master-detail (cross-reference) relationship.
  • Lightning Experience and Salesforce Classic (the behavior is platform-level, not UI-specific).

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.


INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY
 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.

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.

Option A — Run the specific insert in system mode

Use this when the Guest User legitimately needs to create the record but should not be granted broad standing access to the referenced object.

  1. Open the Apex class that performs the insert.

  2. Confirm the class is saved on an API version where the Database method AccessLevel overloads are available (see the version note below).

  3. 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.)

  1. 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.

  2. 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.

Option B — Share the parent record with the Guest User (only if it holds no sensitive data)

  1. Identify the referenced (parent) record the insert points to.
  2. If that record contains no sensitive data, create a sharing rule that grants Guest Users the required access to it.
  3. Re-test the insert as a Guest User to confirm the error no longer occurs.

Option C — Remove Guest User create permission (if the Guest User should not be inserting this object)

  1. If Guest Users should not be creating this object at all, remove the create object permission from the Guest User profile/permission set.
  2. Adjust the site flow so the record is created by an appropriately permissioned context instead.

Security scoping (applies to all options):

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.

Knowledge 기사 번호

005459387

 
로드 중
Salesforce Help | Article