+ Start a Discussion
Shekhar P V PalwankarShekhar P V Palwankar 

Strange behavior with auto number. Has anyone noticed it?

While working with Auto Number I found that the system is skipping few numbers. I observed that if I try to save a record with one of the fields as an Auto Number and any error occurs while saving the record (say the mandatory field is missing/ duplicate value error), then the system simply skips the next number. e.g. I created one record with Auto Number as C-0001, while creating the second record I bumped into errors twice and on saving the same record the record was assigned with Auto Number as C-0004.

Issue with Auto Number 

Logically, a system should increment the Auto Number counter only after a successful transaction. Anyone has ever observed such a behavior? Any solution to take care of this?

Thanks in advance.

Regards,
Shekhar Palwankar
Best Answer chosen by Shekhar P V Palwankar
Amit Chaudhary 8Amit Chaudhary 8
Similer issue in found in test class. Please see below post
1) https://help.salesforce.com/apex/HTViewSolution?id=000176743&

Please check below post as well
1) https://www.sundoginteractive.com/blog/salesforce-auto-number-field-skips-numbers

Let us know if this will help you

Thanks
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Similer issue in found in test class. Please see below post
1) https://help.salesforce.com/apex/HTViewSolution?id=000176743&

Please check below post as well
1) https://www.sundoginteractive.com/blog/salesforce-auto-number-field-skips-numbers

Let us know if this will help you

Thanks
Amit Chaudhary
This was selected as the best answer
CloudyJoshCloudyJosh
So basically to sum things up from the second link,

Scenario: "It appears that each time an Auto-number field is created, the Salesforce platform will create a number incrementor for this field. When a number is requested from this incrementor, the system doesn’t know if the requesting record will be committed or not, so it can’t roll back its incrementor, as this breaks the field’s uniqueness by giving away the same number again. "

Solution: "To opt-in to this new functionality, you have to call Salesforce Support and tell them to ensure your Auto-number fields aren’t incremented by unit tests"

See more at: https://www.sundoginteractive.com/blog/salesforce-auto-number-field-skips-numbers#sthash.QDOA1aDM.dpuf"
Shekhar P V PalwankarShekhar P V Palwankar
Thanks @Amit Chaudhary 8... :)