0

For my accounts I need a text field with some alphanumeric code plus an unique integer value:

myField: "xyz-12345"

It doesn't matter how the integer value is calculated, but it must be unique and it should not be longer than 10 to 15 digits.

Is it possible to calculate the integer from the (unique) accounts ID?

Obi_77
  • 475
  • 8
  • 18
  • 1
    Where does the first part of the text field come from? Would creating a separate auto-number field and concatenating it with a formula fill your need? – Jesse Milburn Aug 29 '16 at 13:16

1 Answers1

9

You can't have a "15-digit integer" that covers all possible Id values. This is because there are 629 possible values in an Id (per object type per pod, plus reserved space), while there's only 1016-1 possible values in your proposed number space.

10^16-1     999999999999999
62^9        13537086546263552

Your best bet is simply an auto-number field, which will be reasonably unique as long as you don't tinker with the "next possible value" setting. Using some sort of hash algorithm would introduce the possibility that there's a possible collision, known as the birthday paradox.

The auto-number field will allow you to have 1010 values before it rolls over, which is probably more than enough number space, given that you'd most likely run out of storage space in your database before you'd roll over.

sfdcfox
  • 489,769
  • 21
  • 458
  • 806