You need to sign in to do that
Don't have an account?
Rockers
How to add 6 digit random number id to the inserted record?
Hi Friends,
I want to add 6digits random to the inserted record which will be used as a unique id for the records. For Example,
In Standard User Object, when an user is created, i need add a value which is alphanumeric combination as follows:
Format:-
ABC[2digit Country Code][xxxxxx].
So, pls help me to solve this one.
Regards,
Phanikumar
double y = Math.random() ; //between 0 and 1
y = 999999 * y;
integer index = math.round(y);//something between 0 and 999999
you will need to check against exisitng numbers generated.
the exact randomness of the above is partially contingent on the double format.
All Answers
google 'salesforce math methods'. There is a random method that returns a double in the range of 0-1. Mutliple this by your range and then use the round function (also via math methods).
Thanks for your valuable reply Friend. Let me try and let you know about the result.
Regards,
Phanikumar
double y = Math.random() ; //between 0 and 1
y = 999999 * y;
integer index = math.round(y);//something between 0 and 999999
you will need to check against exisitng numbers generated.
the exact randomness of the above is partially contingent on the double format.
Hi Rockers,
You can make use of crypto class to get random integer values.
Do try the follwoing code it may help you resolve the issue you are trying to solve.
Integer Rnd = crypto.getRandomInteger();
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thank you Friend...
Its working fine now.
Regards,
Phanikumar