How to generate unique identifier (UUID) using Salesforce Apex?

How to generate unique identifier (UUID) using Salesforce Apex?

To generate unique identifier (UUID) using Salesforce Apex, randomUUID() from UUID class can be used.

Sample Code:

UUID randomUUID = UUID.randomUUID();
System.debug(
    'randomUUID is ' + 
    randomUUID
);
System.debug(
    'randomUUID String value is ' + 
    randomUUID.toString()
);

Leave a Reply