Hi, As such you should see if you can create autonumber field.If not,the basic idea would be like this:-
You can make use of Custom Settings.With custom settings,you have control over number being generated without revisiting the code. You can use this to maintian counter of autonumber. Also, creat a Text Field to store the autonumber being generated. Initialize it with 1.Everytime you create a record,stamp the required field with this number and at last increase the number and update the custom settings. In same custom settings you can store some string pattern like ABC-000 which you can use in code and concatenate it to obtain desired string.
As such you should see if you can create autonumber field.If not,the basic idea would be like this:-
You can make use of Custom Settings.With custom settings,you have control over number being generated without revisiting the code.
You can use this to maintian counter of autonumber.
Also, creat a Text Field to store the autonumber being generated.
Initialize it with 1.Everytime you create a record,stamp the required field with this number and at last increase the number and update the custom settings. In same custom settings you can store some string pattern like ABC-000 which you can use in code and concatenate it to obtain desired string.
Regards
Nitesh
You can use below mentioned code to generate number by setting the upperlimt as well
For more information you can check below mentioned link : https://developer.salesforce.com/blogs/developer-relations/2013/07/selecting-random-numbers-and-records-on-the-force-com-platform-part-1.html
Please let me know if this works for you.
Thanks