Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
UUID Class
Namespace
Usage
The UUID is generated using a cryptographically strong pseudo-random number generator and is represented as 32 hexadecimal values.
UUID Methods
The following are methods for UUID.
equals(obj)
Signature
public Boolean equals(Object obj)
Parameters
- obj: Type: Object The UUID object to be compared.
Return Value
Type: Boolean
Example
1
2// UUIDs are equal when all the characters in the UUID are the same
3String uuidStr = '707b2538-98bb-41e7-95e3-1d77bf42b102';
4UUID fromStr = UUID.fromString(uuidStr);
5UUID fromStr2 = UUID.fromString(uuidStr);
6Assert.isTrue(fromStr.equals(fromStr2));
7
8// A UUID is never equal to a String or any non-UUID object
9Assert.isFalse(fromStr.equals(uuidStr));
10fromString(str)
Signature
public static System.UUID fromString(String str)
Parameters
- str: Type: String
Return Value
Type: System.UUID
Example
1String uuidStr = '707b2538-98bb-41e7-95e3-1d77bf42b102';
2UUID fromStr = UUID.fromString(uuidStr);
3
4UUID.fromString(null); // Throws NullPointerException
5
6UUID.fromString(‘not a uuid’); // Throws IllegalArgumentException
7hashCode()
Signature
public Integer hashCode()
Return Value
Type: Integer
randomUUID()
Signature
public static System.UUID randomUUID()
Return Value
Type: System.UUID
A 32 hexadecimal value of the UUID generated.
Example
1UUID randomUUID = UUID.randomUUID();
2system.debug(randomUUID); // Prints the UUID string that was randomly generated
3toString()
Signature
public String toString()
Return Value
Type: String