Advertisement
Guest User

Untitled

a guest
May 20th, 2019
2,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public static void handleAfterInsert(List<Account> newAccounts){
  2.  
  3. Id runningUserId = UserInfo.getUserId();
  4. //Week 7 Homework - bulkify this code
  5.  
  6. List<Case> casesToInsert = new List<Case>{};
  7.  
  8. for (Account a : newAccounts) {
  9.  
  10. Case c = new Case();
  11. c.Status = 'New';
  12. c.Origin = 'New Account'; //Make sure you've added this as a picklist value for this field
  13. c.Subject = 'Send Welcome Package';
  14. c.AccountId = a.Id;
  15. c.Description = 'Please follow up with this new Account and send them a Welcome Package.';
  16. casesToInsert.add(c);
  17. //Get the email address for the Account owner
  18. User u = [SELECT Id, Email FROM User WHERE Id = :runningUserId];
  19. c.Staff_Email_Address__c = u.Email;
  20.  
  21.  
  22. }
  23. insert casesToInsert;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement