One of my clients asked me to implement a solution that automatically assigns a custom non-SF ID to all Contacts upon creation or update of the record.
The custom ID should be alphanumeric and look like the following: AB1231
- randomly generate 2 letters
- randomly generate 3 digits
- calculate and append a verification number
- replace letters with their alphabetical index
- all digits with modulo 10
- multiply all digits alternately by 1 and 2
- calculate the check sum from each product
- add check sums together
- sum modulo 10
If we randomly generated KW940
, then the verification number must be 4
- K = 11, W = 23 ==> Therefore, the sequence is
11 23 9 4 0
- with modulo ==>
1 3 9 4 0
- multiplied by 1s or 2s ==>
1 6 9 8 0
- with check sum ==>
1 6 9 8 0
- all added together ==>
24
- modulo of 24 ==>
4
The ID therefore isKW9404
.