function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phuc Nguyen 18Phuc Nguyen 18 

How to auto increment Object Name when created or deleted

Hello All,
Need some help creating a process for creating an object name.  So the name will be a text value plus an auto incremetnted value.
For example Opportunity created would be 'Test_001 '
But what if the count is up to Test_089 and they need to delete 5 opportunities and the opportunities are in different sequences?  So they need to delete Test_055 and Test_041 and Test_020.  The naming needs to stay in sequencial order.  Is this possible?
How do I handle the naming when they do a data load?   
Thanks,
P
Best Answer chosen by Phuc Nguyen 18
RituSharmaRituSharma
Create an auto number field. No need to display on screen. Create a workflow rule or process builder and set name as Test_ plus value of auto number field. 

All Answers

RituSharmaRituSharma
Create an auto number field. No need to display on screen. Create a workflow rule or process builder and set name as Test_ plus value of auto number field. 
This was selected as the best answer
AbhishekAbhishek (Salesforce Developers) 
Can you check this developer discussion too,

https://stackoverflow.com/questions/2214141/auto-increment-after-delete-in-mysql
Phuc Nguyen 18Phuc Nguyen 18
Thank you both for the replies.  RituSharma, will your approach work if a user deletes opportunity records?  Thank you.
RituSharmaRituSharma
Let's say you have 4 opportiunities with auto number as 01, 02, 03 and 04. Now you have deleted 02 and then you create a new one. So the auto number field of the new one will have 05. 02 is gone now and SF will not give this auto number to any opportunity.