ジョブがエラーをスローするたびにエラー情報を保存するカスタムオブジェクトを作成し、エラーが発生した場合にメールアラートを送信するワークフロールールをこのオブジェクトに設定できます。
次に例を示します。
より具体的な複数の項目に分割することもできますが、エラーログのカスタムオブジェクトにはカスタム項目 Trace__c のみがあります。
このため、スケジュールする Apex クラスで catch ステートメントに新しいエラーログオブジェクトを作成し、ジョブが失敗した場合に特定のエラー情報を記録します。
try{
//Some DML statement
} catch (Exception e) {
Error_Log__c log = new Error_Log__c();
log.trace__c = 'Type: ' + e.getTypeName() + '\n' + 'Cause: ' + e.getCause() + '\n' + 'Message: '
+ e.getMessage() + '\n' + 'Line #: ' + e.getLineNumber() + '\n' + e.getStackTraceString() + '\n'
+ 'Some Custom Variable Information From Class: ' + myClassVariable;
insert log;
}
次に、新しいエラーログが作成されるたびにメールを送信するワークフローをエラーログオブジェクトに設定できます。そこで使用するクラスに応じて異なる情報を追加できるため、柔軟性があります。
ただし、この目的でカスタムオブジェクトを使用し、エラーデータを保存する場合、このオブジェクトを監視して定期的に古いエラーログを削除する必要があります。30 日以上前のデータは毎月実行される一括処理クラスを使用して削除できます。
この方法の利点は、問題がある場合にのみアラートが通知されることです。スケジュールされたクラスが多数ある場合は、ジョブ完了時にメールを送信することもできます。ただし、多数のクラスうち、一部が毎夜実行される場合、問題がないことを単に通知するためにメールを送信する必要はありません。メールは問題が生じた場合にのみ送信します。
000387981

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.