Use the Independent Auto-Number Sequence Test Option
The Independent Auto-Number Sequence setting helps to avoid gaps in auto-number fields
caused by test records created in Apex tests. This option isolates the auto-number sequence used
in Apex tests from the sequence used in your org. As a result, the creation of test data in Apex
tests doesn’t cause the sequence ofauto-number fields to be higher for new non-test
records.
Required Editions
Available in: Lightning Experience
Available in: Enterprise, Performance,
Unlimited, Developer, and Database.com Editions
User Permissions Needed
To define, edit, delete, set security, and set version settings for
Apex classes:
Author Apex
To run Apex tests:
View Setup and Configuration
If this option isn’t enabled, there will be gaps in the
auto-number field whenever Apex tests create test records with auto-number fields. For example,
if Account has an auto-number field, and there are 50 account records in your organization, the
field value of the last created account can be N-0050. After running an Apex
test that creates five test accounts, this causes the auto-number sequence to be increased by
five even though these test records aren’t committed to the database and are rolled back. Next
time you create a non-test account record, its auto-number field value will be
N-0056 instead of N-0051, hence, the gap in the sequence. If
you enable this option before running an Apex test that creates test data, the auto-number
sequence is preserved and the next non-test record will have a contiguous auto-number value of
N-0051.
Gaps in the auto-number sequence can still occur in
other situations, for example, when triggers that attempt to insert new records fail to execute
and records are rolled back. In this case, gaps can’t be completely avoided because, in the same
transaction, some records can be successfully inserted while others are rolled back.
Click Options....
Select Independent Auto-Number Sequence.
Click OK
Did this article solve your issue?
Let us know so we can improve!
Loading
Salesforce Help | Article
Cookie Consent Manager
General Information
Required Cookies
Functional Cookies
Advertising Cookies
General Information
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
Always Active
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
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
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.