Skip to main content
Nintex Community Menu Bar
Question

check if a string is a salesforce id

  • Jul 11, 2024 11:57 AM UTC
  • 3 replies
  • 942 views
  • Translate All

Forum|alt.badge.img+18

Anyone have a good way to perform a check on a string to see if it is a salesforce id, beyond ensuring that it’s 18 characters long?

3 replies

Forum|alt.badge.img+17

I think the first 3 characters are the object ID, so you could check to make sure the string has 18 characters and begins with a 3 character string that matches one of the objects you are receiving these id’s from.

Translate

Forum|alt.badge.img+10
  • Nintex Employee
  • Jul 11, 2024 12:32 PM UTC

Are you checking just a string itself, or is there metadata available that you could also check (checking for field type, for example)?

Translate

Forum|alt.badge.img+18
  • Author
  • Jul 11, 2024 12:32 PM UTC

Hmm, that might work, Raymond… but to make the solution portable between orgs I’m going to have to dynamically get the first three characters of the objects in question. Is there a simple way to do that beyond building a model on the object to query it and check the id?

Here’s what I’m doing right now. It’s obviously not foolproof, but should work 99% of the time for our use case.

string.length === 18 && string.match(/[A-Za-z0-9]/)

Translate