public class GenerateSampleDataBatch implements Database.Batchable, SandboxPostCopy {
public class GenerateSampleDataBatch implements Database.Batchable<sObject>, SandboxPostCopy {
public void runApexClass(SandboxContext context) {
Database.executeBatch(this);
}
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([SELECT Id FROM Account LIMIT 1]);
}
public void execute(Database.BatchableContext bc, List<sObject> scope) {
List<Account> accountsToInsert = new List<Account>();
List<Contact> contactsToInsert = new List<Contact>();
String[] accountNames = new String[] {
'Devbug','Oyoba','Realblab','Skyvu','Quamba','Mybuzz','Skinix','Buzzbean',
'Blogtag','Wikibox','Quire','Blognation','Cogidoo','Ntag','Jayo','Tagchat',
'Skyble','Jaloo','Zoovu','Brainbox','Pixonyx','Leenti','Geba','Skalith',
'Browsebug','Skipfire','Digitube','Babbleset','Skiptube','Aimbu','Eayo',
'Dablist','Fivespan','Mydo','Centizu','Voonte','Zoonoodle','Centimia',
'Eamia','InnoZ','Oba','Rhycero','Voonix','Dablist TX','Topicshots','Babbleblab','Voonder'
};
String[] contactNames = new String[] {
'Trevion Forman', 'Danika Tejeda', 'Kenyon Burk', 'Isai Valencia', 'Truman Raymond',
'Molly Deloach', 'Izaiah Herrick', 'Kristal Pryor', 'Jarvis Bledsoe', 'Christianna Escamilla',
'Gerald Fields', 'Lincoln Holcomb', 'Brant Platt', 'Josue Green', 'Karina Zhu',
'Kaeli Pagan', 'Jamya Schilling', 'Hallie Griffiths', 'Mara Swisher', 'Hugh Wilcox'
};
String[] emailDomains = new String[] {
'@gmail.com', '@swantide.com', '@hotmail.com', '@Aol.com', '@Outlook.com', '@Teams.com', '@mail.com', '@icloud.com'
};
for (Integer i = 0; i < 100; i++) {
Integer randomIndex = Math.mod(Math.abs(Crypto.getRandomInteger()), accountNames.size());
String randomName = accountNames[randomIndex];
Account acc = new Account();
acc.Name = randomName;
acc.Industry = 'Technology';
acc.Phone = '123-456-7890';
accountsToInsert.add(acc);
}
insert accountsToInsert;
for (Account acc : accountsToInsert) {
for (Integer j = 0; j < 5; j++) {
Integer randomNameIndex = Math.mod(Math.abs(Crypto.getRandomInteger()), contactNames.size());
String randomContactName = contactNames[randomNameIndex];
String[] nameParts = randomContactName.split(' ');
Integer randomDomainIndex = Math.mod(Math.abs(Crypto.getRandomInteger()), emailDomains.size());
String randomDomain = emailDomains[randomDomainIndex];
Integer randomNum = Math.mod(Math.abs(Crypto.getRandomInteger()), 10000);
Contact con = new Contact();
con.FirstName = nameParts[0];
con.LastName = nameParts[1];
con.Email = nameParts[0].toLowerCase() + randomNum + randomDomain;
con.AccountId = acc.Id;
contactsToInsert.add(con);
}
}
insert contactsToInsert;
}
public void finish(Database.BatchableContext bc) {
System.debug('Batch execution finished.');
}