trigger CreateContactsOnAccountCreationTrigger on Account (after insert) {
// Loop through the newly inserted Accounts
for (Account account : Trigger.new) {
// Create 3 Contacts with the same name as the Account
for (Integer i = 1; i <= 3; i++) {
Contact newContact = new Contact();
newContact.LastName = account.Name;
newContact.AccountId = account.Id;
insert newContact;
}
}
}
dHJpZ2dlciBDcmVhdGVDb250YWN0c09uQWNjb3VudENyZWF0aW9uVHJpZ2dlciBvbiBBY2NvdW50IChhZnRlciBpbnNlcnQpIHsKCiAgICAvLyBMb29wIHRocm91Z2ggdGhlIG5ld2x5IGluc2VydGVkIEFjY291bnRzCiAgICBmb3IgKEFjY291bnQgYWNjb3VudCA6IFRyaWdnZXIubmV3KSB7CgogICAgICAgIC8vIENyZWF0ZSAzIENvbnRhY3RzIHdpdGggdGhlIHNhbWUgbmFtZSBhcyB0aGUgQWNjb3VudAogICAgICAgIGZvciAoSW50ZWdlciBpID0gMTsgaSA8PSAzOyBpKyspIHsKICAgICAgICAgICAgQ29udGFjdCBuZXdDb250YWN0ID0gbmV3IENvbnRhY3QoKTsKICAgICAgICAgICAgbmV3Q29udGFjdC5MYXN0TmFtZSA9IGFjY291bnQuTmFtZTsKICAgICAgICAgICAgbmV3Q29udGFjdC5BY2NvdW50SWQgPSBhY2NvdW50LklkOwogICAgICAgICAgICBpbnNlcnQgbmV3Q29udGFjdDsKICAgICAgICB9CiAgICB9Cn0K