Apex トリガ実行時に「execution of [EventName] caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.[TriggerName]: line [XX], column [XX]」エラーが発生することがあります。
これは、インスタンス化されていないオブジェクトや初期化されていない属性を使用しようとした場合に起こります。
解決策は、オブジェクトや属性が null でないことを確認することです。
注: 項目 Site を空のままにした場合にも同様のエラーメッセージが生成されます。
問題の解決
解決方法は、使用されているオブジェクトおよび/または属性が null でないことを確認することです。 この例では、コードを次のように変更する必要があります。
Account newAccount = accountMap.get(oldAccount.Name);
if (newAccount != null)
if (newAccount.Site != null)
i = newAccount.Site.length();
次のような例外処理ルーチンを使用できます:
Account newAccount = accountMap.get(oldAccount.Name);
try {
i = newAccount.Site.length();
}
catch (System.NullPointerException e) {
e1 = e; // can be assigned to a variable to display a user-friendly error message
}
例外の処理に関する詳細な情報については、「Apex 開発者ガイド」の「Exception クラスおよび組み込み例外」を参照してください。
変数の初期化に関する詳細な情報については、「データ型および変数」のトピック「変数」および「大文字と小文字の区別」を参照してください。
000385601

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.