Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for the formula used by Salesforce on Data Type: Auto Number fields.

I assumed it was sequential (increases by 1 from the last number generated), but according to our data, it doesn't seem true:

Record created 7:32 AM = 0003288395; Record created 9:06 AM = 0003289295. An hour an a half later and the number is 900 higher. According to a report of all records created and sorted by this number field, there are no numbers in between them unless 900 records were deleted - which I confirmed is not the case in our Recycle Bin.

share|improve this question
up vote 3 down vote accepted

If you run test methods, and don't opt to preserve sequencing (it's in the test running page under the options button), any tests you run will cause gaps. Also, failed transactions can cause gaps unless you enable the anti-gap function available by contacting support.

share|improve this answer
Thanks, again, I can confirm no test ran during this time period. By failed transaction, I'm assuming you mean a failure to insert? – zainogj Jul 18 '14 at 15:45
There may be failed transactions that caused the gap. Do you have any integrations that may have been loading data, or triggers that may have failed, etc? – sfdcfox Jul 18 '14 at 15:47
Got it, absolutely. I'll dig in a little more. – zainogj Jul 18 '14 at 15:48
That seems to be true. I feel like a fool for never noticing that. We've had a batch process which runs (not even sure how long it's been active) which has failures in it. Thanks again. – zainogj Jul 18 '14 at 16:02

Autonumbers are also used up in unit tests, although you can turn on a setting in tests to disable this.

This is under setup | develop | apex test execution | options

enter image description here

share|improve this answer
Thanks, that does appear useful and good to know, but it doesn't seem like that resolves my issue. Just like the recycle bin, I don't know of any APEX test executions that occurred between those record entries. Even looking at our APEX Test results, I'm not seeing any tests during this time period. – zainogj Jul 18 '14 at 15:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.