Created
September 25, 2017 16:49
-
-
Save coder36/484468496042acd677086d06f46011f5 to your computer and use it in GitHub Desktop.
Apex Guid generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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