+ Start a Discussion

Random Generated Number



My question to the SF Minds. I am looking to use the auto numbering in SF. My question is, can SF generate an auto number in an Opp? My anwser to that is yes. But can it generate a random number like:


Example: Opportunity number 13-5262, then the next Opportunity to be created would look like this 13-4598. 


The 4 digits should be a computer generated, non-sequential, completely randomized number so as to not allow how many opportunities we are aware of to be publicized.


Any ideas on how I could create this in SF?


Thank you SF Minds!



To expand just a bit... You'll create a text field as long as you need it to be, and then you'll need a trigger. The trigger will assign a new number each time an opportunity is created or updated and is missing its number (for historic records). You can have this trigger also check the prior value on update and cause it to revert back in the event that a user tries to modify the number.


Hi You can generate Random number of your range as by going through the below link




And you can suffix "13-" in the beginng to that as string fromat.

Hi Hasha,

Have you used this? I copied this "Randomizer" code into my sandbox. Now Im not sure how I am able to view this. What would be the next steps to getting this to work? Sorry very new to this and I kinda understand. Any advise or help would be greatly appreciated.


Hi Shawn, 


Now you can just use the methods of the Randomizer class directly in any of the class in that package where you created the Randomizer class.


As shown in the link that i provided.