Salesforceの自動採番項目で番号に抜け(欠番)が発生する事象について解説します。
本記事では、欠番が発生する主な原因を具体的に説明します。
はじめに:自動採番の仕様
Salesforceの自動採番項目は参照のみの項目であり、内部オブジェクト ID に依存しない一意な ID を提供します。
自動採番項目は、レコードが作成されるたびに一意の番号を自動的に割り当てますが、Salesforce の仕様上「自動採番項目」に関しては、値が連続することを保証していません。
そのため入力規則などのエラーにより レコードの作成に失敗した場合や Apex のテストメソッドが走った場合などに、自動採番項目が欠番になることがあります。
欠番は、レコードを保存するトランザクションが完了する前に番号が割り当てられ、その後の処理でレコードの作成が失敗した場合に発生します。
代表的な原因は以下の通りです。
・入力規則や必須入力項目エラーではじかれた場合
※ 必須入力のエラーは内部ロジック上、連番を確保した後に評価されるため連番が飛ぶことになります。
・ Apex のテストメソッドが走った場合 (Apex テストのオプションで「独立した自動採番順序」が無い場合)
・ レコードが削除された場合
・ タイムアウト等の内部的なエラーが発生してロールバックが発生し、レコードが作成されなかった場合
・ 自動採番項目のカウンターがリセットされた場合(カスタムオブジェクトの場合のみ)
000386388

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.