Skip to content

Instantly share code, notes, and snippets.

@coder36
Created September 25, 2017 16:49
Show Gist options
  • Save coder36/484468496042acd677086d06f46011f5 to your computer and use it in GitHub Desktop.
Save coder36/484468496042acd677086d06f46011f5 to your computer and use it in GitHub Desktop.
Apex Guid generator
trigger ContactGuidGenerator on Contact (before insert) {
for( Contact c: Trigger.new ) {
Blob b = Crypto.GenerateAESKey(128);
String h = EncodingUtil.ConvertTohex(b);
String guid = h.SubString(0,8)+ h.SubString(8,12) + h.SubString(12,16) + h.SubString(16,20) + h.substring(20);
c.guid__c = guid;
// guid should be Text, size 32
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment