Guest User

Untitled

a guest
Oct 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. trigger tokenGenerator on Certification__c (before insert) {
  2. static string randomString(){
  3. for(Certification__c c: Trigger.new){
  4. final String chars = 'BCD';
  5. String a = '';
  6. while (a.length() < 1) {
  7. Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length());
  8. a += chars.substring(idx, idx+1);
  9. }
  10. }
  11. return a;
  12. }
  13. Integer i;
  14. if(i<100){
  15. while(c.Name.contains(a)){
  16. randomString();
  17. i++;
  18. }
  19. c.Name = a;
  20. }
  21. else
  22. c.Name = 'You ran out of TOKENS';
  23. }
Add Comment
Please, Sign In to add comment