Loading

AccountID Shows as Null in Before Insert or Before Update Case Trigger During Email-to-Case or Manual Case Creation

Fecha de publicación: Jun 2, 2026
Descripción

When a Case record is created in Salesforce — either manually from a Contact record's related list, or via Email-to-Case — developers may observe that the AccountId field is null in Before Insert or Before Update Apex trigger events, even when both a Contact and its related Account are assigned to the Case. This behavior occurs specifically for non-administrator users when the Account field on the Case page layout or field-level security is set to Read-Only.


When a Standard User creates a Case from a Contact's related list with the Account field set to Read-Only, the AccountId is not populated in Trigger.new during the Before Insert event. System Administrators are not affected because they have full field visibility. The AccountId is correctly populated just before the After Trigger events in the order of execution, once the record is saved and the Contact-Account relationship is resolved.

 

Solución

This behavior is considered working as designed. Because the Account field is Read-Only for the Standard User (as determined by field-level security or the page layout), the AccountId is resolved from the database via the Contact record's relationship — a process that occurs after the Before Trigger events. During the Before Insert trigger, the AccountId has not yet been populated for users without edit access to the Account field.

Recommended Workarounds

Choose one of the following workarounds based on your implementation requirements:


Option 1: Make the Account Field Editable Make the Account field on the Case object editable for non-administrator users by updating both the field-level security settings and the Case page layout. This allows Salesforce to populate AccountId in the Before Insert trigger.


Option 2: Move Trigger Logic to After Trigger Context Move the trigger logic that depends on AccountId into the After Insert or After Update trigger context. In the After trigger context, AccountId is fully populated and accessible for all user profiles.


Option 3: Query the AccountId in the Before Insert Trigger In the Before Insert trigger, programmatically retrieve the AccountId by querying the Contact record using the ContactId from Trigger.new. Assign the Contact's AccountId to the Case's AccountId field within the trigger.

Note: the query approach requires a SOQL query per trigger invocation — ensure you are following bulkification best practices.

Número del artículo de conocimiento

000387008

 
Cargando
Salesforce Help | Article