For ex: If I create a new Account, does salesforce algorithm always generate a new record Id or it looks for any of the old deleted record and assigns that Id?


No, new records always receive new IDs, and they are generally allocated in sequential order within the same transaction (but, not guaranteed, so do not depend on that behavior). The only exception to ID re-use are in sandboxes, where records copied to the sandbox will share the same ID as those in the production environment they came from. Multiple sandboxes, for example, can have the same record with the same ID. Newer records will always have an ID that is numerically higher than older records (where newer and older refer to the moment of the initial commit in the salesforce transaction lifecycle).

It's worth noting that some day, ID values might wrap around and we'd see ID reuse, as the ID key space is only 62^9 (13,537,086,546,263,552) values large, with the remaining six characters serving some other purpose (three for key prefix, and three for other purposes, mostly for pod identification so far). I don't think I've observed a single as large as 56,800,235,584 (six characters), so they're not even 1% of the way through their total space for a single key prefix. Of course, I can't see all ID values, such as deployments, etc, so it's possible some of them have exceeded those values, but not by too much, I'd assume.

  • hi @sfdcfox is there a salesforce doc reference which says the behavior of record ids when we refresh a sandbox please if you have seen any? is it always copied over? Couldn't find any official note on it. Thanks. Apr 26 '18 at 23:05
  • 1
    @PasanEeriyagama I haven't seen any. It's based on personal experience and could change at any time. However, based on the complexity of replicating an entire org, I doubt they'll change it any time soon. Still, I also would not rely on this behavior.
    – sfdcfox
    Apr 26 '18 at 23:56
  • Thanks @sfdcfox I think I found some info. here. Apr 27 '18 at 1:16
  • @PasanEeriyagama Oh, great, there is a document for that. I'll update my answer.
    – sfdcfox
    Apr 27 '18 at 1:17
  • I did have a case where an org was potentially having an issues as it was clearing down and re-uploading millions of records a day. As a result each record was getting new id's but they still had 10 years before they would run out and start reusing id's . Also running unit tests creates and deletes records which could also use the pool if Ids although I think the id's now go back into the pool for re-use. So potential for dupes then.
    – Francis
    Aug 27 '21 at 10:30

How do unique IDs work in Salesforce?

It will always generate a new ID and will not reuse IDs from deleted records.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.