-
-
Save doppiomacchiatto/c2d4ebfed5fd34d2833c7f7480880198 to your computer and use it in GitHub Desktop.
Apex random string 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 ) { | |
final String chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; | |
String guid = ''; | |
while (guid.length() < 16) { | |
Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length()); | |
guid += chars.substring(idx, idx+1); | |
} | |
c.guid__c = guid; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment