function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ram_iyerram_iyer 

How to create UUIDs in Salesforce

Hi,

 

I have a requirement to generate UUIDs for associating IDs that are unique across 2 apps - one SF and another external app. There is a Java utility that allows creation of UUIDs. Is there a similar API that can be used for generating UUIDs in Apex?

 

Regards,

Ram

simsonsimson

Hi All,

I too have a requirement to generate UUID from within SF.

In java the class to generate uuid is called java.util.UUID.

 

Can we use the Crypto Class for this purpose?

Can i use the generateMac method of the Crypto Class to acheive this?

 

Simson.

simsonsimson

In Apex-Lang we have utility methods for generating uuid's.

The Class RandomStringUtils in Apex-Lang contains a method randomUUID().
Can we use this method to generate the uuid.

This method uses the Version 4 UUIDs scheme relying only on random numbers. 

 

 

ram_iyerram_iyer

There are a few webservices that are available that provide UUIDs. We've used one of these by making a webservice call from Salesforce.