メール-to-ケース を介してケース を作成すると、ContactId 項目が正しく設定されていても、before insert トリガーのコンテキストでは AccountId 項目が null になる現象が発生します。
再現手順:
before insert トリガーを作成します。trigger DebugCaseValues on Case (before insert) {\
for (Case c : Trigger.new) {
System.debug('##### Case values: ' + c);
}
}
before insert コンテキストで AccountId 項目が null であることが示されます。##### Case values: Case:{Id=null, ..., ContactId=003..., AccountId=null, ...}
この挙動は設計通りの動作です。
Salesforce は、ケースを関連付けられた取引先責任者の取引先に正しく関連付けるために、内部的な事後処理を実行します。この処理は、レコードがデータベースにコミットされた後(つまり、after insert 後)に発生します 。プラットフォームがケース 、取引先責任者 、取引先間のリレーションを最終決定 していないため、before insert トリガーの間は AccountId を利用できません。
005132457

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.