-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create-Accounts-and-Contacts.apex
45 lines (36 loc) · 1.05 KB
/
Create-Accounts-and-Contacts.apex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
A sample Apex Script to generate test data.
*/
List<Account> accounts = new List<Account>();
List<Contact> contacts = new List<Contact>();
for(Integer i = 0;i<10;i++){
String iStr = String.valueOf(i);
Account a = new Account(
Name = 'Acme ' + iStr,
BillingStreet = iStr + '89 Main Street',
BillingCity = 'Philly',
BillingState = 'YO',
BillingPostalCode = '1911' + iStr,
NumberOfEmployees = 10 * i,
Phone = '(215) 555-121' + iStr);
accounts.add(a);
}
insert accounts;
//Outer loop to cycle through our created Accounts
for(Account acct:accounts){
//Inner loop to cycle through 10 records
for(Integer j = 0;j<10;j++){
String jStr = String.valueOf(j);
Contact c = new Contact(
AccountId = acct.id,
FirstName = Math.mod(j,2) > 0 ? 'Jane' : 'John',
LastName = 'Smithwick, ' + jStr,
MailingStreet = jStr + '89 Main Street',
MailingCity = 'Philly',
MailingState = 'YO',
MailingPostalCode = '1911' + jStr,
Phone = '(215) 555-121' + jStr);
contacts.add(c);
}
}
insert contacts;