Please follow the code below :
1 2 3 4 5 6 7 8 9 10 | trigger generateRandom on Contact (before insert) { for(Contact con: Trigger.new) { if(trigger.isBefore && trigger.isInsert){ String str = string.valueof(Math.abs(Crypto.getRandomLong())); String randomNumber = str.substring(0, 7); con.Random_ID__c= randomNumber; } } } |
0 Comments