Why is AccountId null in my Before Insert/Update Case trigger?
|Knowledge Article Number||000221321|
|Description||When you create or edit a Case, you might notice that you cannot access the AccountId in certain scenarios. Below we will go through a reproducible scenario and state the result.
In the results, we can see that, for the Standard User, the AccountId is returns null in the Before Insert event when both Account and Contact are being assigned on the Case creation.
|Resolution||This result is considered to be working as designed due to the complexity of the implementation of the relationship between the Case, Contact, and Account records.
Because the Account field is Read-Only (as determined either by page layout or field-level security), the AccountId is being reviewed in the database via the Contact record passed resulting in the AccountId being null in the Apex Trigger. Once saved, just before the After Trigger events in the order of execution, the correct Id will be populated.
You can use the following workarounds: