Generate UUID in Apex
Easily generate UUID in Apex
UUID, or Universally Unique Identifier, is a 128-bit label with a probability of duplication considered close enough to zero to be negligible.
Ever needed a UUID in Salesforce?
UUID, or Universally Unique Identifier, is a 128-bit label with a probability of duplication considered close enough to zero to be negligible.
bash
02c90c10-dc3f-4478-8ac5-fa869de4b061You don't need to build your own class to obtain the UUID in Apex. To retrieve UUID v4, all you have to do is use this one-liner:
apex
(String)((Map<String,Object>) JSON.deserializeUntyped(new Auth.JWT().toJSONString())).get('jti')The code snippet is also pasted in the first comment, ready for you to copy!


