Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void handleAfterInsert(List<Account> newAccounts){
- Id runningUserId = UserInfo.getUserId();
- //Week 7 Homework - bulkify this code
- List<Case> casesToInsert = new List<Case>{};
- for (Account a : newAccounts) {
- Case c = new Case();
- c.Status = 'New';
- c.Origin = 'New Account'; //Make sure you've added this as a picklist value for this field
- c.Subject = 'Send Welcome Package';
- c.AccountId = a.Id;
- c.Description = 'Please follow up with this new Account and send them a Welcome Package.';
- casesToInsert.add(c);
- //Get the email address for the Account owner
- User u = [SELECT Id, Email FROM User WHERE Id = :runningUserId];
- c.Staff_Email_Address__c = u.Email;
- }
- insert casesToInsert;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement