You need to sign in to do that
Don't have an account?

Random numbers in Apex?
Hi there,
I'm trying to best determine how to randomly segment my contacts. Is there a way to generate a random number in Apex to update all or selected contacts?
I have little to no success with 'true' random number generation with formulaic fields.
Thanks!
Darrell
I'm trying to best determine how to randomly segment my contacts. Is there a way to generate a random number in Apex to update all or selected contacts?
I have little to no success with 'true' random number generation with formulaic fields.
Thanks!
Darrell
You may be better off looking at the ContactID. As it is added sequentially you could use the last 1 or 2 characters to assigne a psedu - random distribution of the contacts.
GlennW
Double rnd = Math.random();
which you can then use to pick an index from an array of contacts.
I created a randomization class in APEX that might do what you need. You can download the class and see useage examples on my blog:
http://codebycody.com/2012/02/29/sfdc-randomizer/
Hope this helps,
Cody