4

With reference to the very informative What are Salesforce ID's composed of?, I am wondering what the best value to use for an Id of a specific SObjectType that matches nothing is.

If I understand that link correctly, the Id should be something like:

SObjectType t = ...;
Id id = t.getDescribe().getKeyPrefix() + '000' + 'xxxxxxxxx';

But what is a good value to use in place of 'xxxxxxxxx' e.g.:

'zzzzzzzzz'
'ZZZZZZZZZ'
'ZzZzZzZzZ'
'000000AAA'
'NoMatchId'
'xxxxxxxxx'
2
  • I use fflib_IDGenerator and it uses 00000000 and each time new Id is generated it keeps a track so next time you ask for new Id it doesnt get repeated Sep 24, 2019 at 15:49
  • Hi @PranayJaiswal, Its an Id value that can be thrown into queries and match nothing rather than just a random Id that might match something in the database that I'm looking for. Thanks for the comment though.
    – Keith C
    Sep 24, 2019 at 15:52

1 Answer 1

5

You can use all zeroes (e.g. keyPrefix + '0'.repeat(12)). It will never match an existing or future ID. Depending on your use case, you can also generally just use '0'.repeat(15), which is what Salesforce uses internally to represent a null ID. Obviously, the 0-key-prefix pattern doesn't match a specific sObject, but might be valid for some use cases. Note that this presumes you're using 15-character ID values. If you calculate the parity bits at the end, remember it may not always be AAA, so consider Id.valueOf(keyPrefix+'0'.repeat(12)) instead to get the correct suffix.

1
  • The zeroes sound good. I do want to keep the key prefix as down the line code uses the type of the Id. Thanks!
    – Keith C
    Sep 24, 2019 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .