By Burcu Derdiyok
public class AutomatedTestDataEntry {
public static void newAccountGenerate(List<Account> acList) {
for(Account newAccount: acList) {
if(newAccount.Fill_Test_Data__c == true) {
newAccount.Phone = generatePhoneNumber();
newAccount.AnnualRevenue = generateAnnualRevenue();
newAccount.Active__c = 'Yes';
newAccount.Description = 'New account created by automatically.';
newAccount.Industry = generateIndustry();
}
}
}
public static String generateRandomValueFromList(List<String> myList) {
Integer index = Math.mod(Math.round(Math.random() * 100), myList.size());
return myList.get(index);
}
public static String generatePhoneNumber() {
List<String> myList = new List<String>{'0','1','2','3','4','5','6','7','8','9'};
String phoneNumber = '';
for(Integer i = 0; i < 10; i++) {
Integer index = Math.mod(Math.round(Math.random() * 100), myList.size());
phoneNumber += myList.get(index);
}
return phoneNumber;
}
public static String generateIndustry() {
List<String> myList = new List<String>{'Agriculture', 'Apparel', 'Banking', 'Biotechnology', 'Chemicals', 'Communications', 'Construction'};
String Industry = '';
Integer index = Math.mod(Math.round(Math.random() * 100), myList.size());
Industry = myList.get(index);
return Industry;
}
public static Integer generateAnnualRevenue() {
List<Integer> myList = new List<Integer>{1000, 2500, 500, 7500, 12000, 3000, 800, 6000, 15000, 200};
Integer AR;
Integer index = Math.mod(Math.round(Math.random() * 100), myList.size());
AR = myList.get(index);
return AR;
}
}
trigger AccountTrigger on Account (before insert, before delete, before update, after insert, after delete, after undelete, after update) {
if (Trigger.isInsert && Trigger.isBefore) {
AutomatedTestDataEntry.newAccountGenerate(Trigger.new);
}
}