function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SteveSteve 

Sequential id's

 

Does anyone know how id's are given out for a custom entity Salesforce?

I presumed that the last 15 characters (case sensitive) followed a sequence "0-9" then "A-Z" and then "abcdefghijklmnopqrstuvwxyz". It seems to be sequential for a while and then jumps forward.

e.g. 000A, 000B, 000C, 000D and then 021C

The reason for this is that I am developing an sControl to generate a sequential number such as an order number.

I do this by inserting a record into a custom enitity which returns a unique id each time, I then convert it to a number using the following function:

calculate(salesforceId.substring(4,15))

function convert(input) {
var convertBase="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var  origin;
var  dest;
var origin=61;
var dest=10;
var b=0;
var Result="";
if (Number(origin)>convertBase.length || Number(dest)>convertBase.length || Number(origin)<2 || Number(dest)<2) return "Invalid numbering system"
for (var c=1;c<=input.length;c++) { b+=convertBase.indexOf(input.substring(c-1,c))*(Math.pow(origin,input.length-c)); if
(convertBase.indexOf(input.substring(c-1,c)) > Number(origin)) return 'Character "'+input.substring(c-1,c)+'" not present in origin system'; }
var a=Math.floor(Math.log(b)/Math.log(dest))
while (a>-1) {
  var e=Math.pow(dest,a)
  a--;
  var d=(b-b%e)/e+1;
  b%=e;
  Ciffer=convertBase.substring(d-1,d);
  Result+=Ciffer;
  }
return Result
}

The problem is that every so often the sequence breaks.

 

ghgh
I have the same question to solve a similar problem. Did you find an answer?
DevAngelDevAngel

Hi Steve,

The id portion after the first 3 digits are sequential, but against all objects in your instance.

This means that if you create an order (order = 1), then an account(account = 2), then a contact(contact=3), then an order (order=4) the ids are despensed in order, but across all data.

order 1= 00R000000000001

account 2 = 00A000000000002

contact 3 = 00C000000000003

order 2 = 00R000000000004

 

SteveSteve

Hi Dave,

Thanks for your reply. That answers my question.

I hear that a sequential number field will be available in the Summer release so that will solve the problem.

In the interim I have used an Custom Entity to store a count which gets incremented. I know there is a slight chance of concurrency but it's acceptable for the moment as the chances of numbers being generated at the same time is very slim.

Thanks,

Steve