Guest User

Untitled

a guest
Apr 16th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. public with sharing class WeekSevenHomework {
  2.  
  3. //Assignment: The following method is supposed to create the number of accounts specified in the argument that it takes.
  4. //Each Account should be named 'Sample Account #sampleNumber' where sample number is the count. So if you created 2 Accounts
  5. //one would be called 'Sample Account 1' and the other 'Sample Account 2'
  6.  
  7. //Also, when we're done inserting them, we will create a case for each one with a Status of 'New', Origin of 'New Account' and the
  8. //desription and subject of your choice.
  9.  
  10. //This isn't working quite right. Can you use your debugging skills to fix it? I had to comment it out since it won't compile
  11. //Look out for consistency and formatting too! (even if they don't break the code)
  12. //Add comments to describe what the code is doing.
  13. //After you get it to compile, run it in execute anonymous and check that it's really working! Look up your new accounts in your org!
  14.  
  15. public static void createSampleAccounts (Decimal numberOfAccounts) {
  16.  
  17. List<Account> acctList = new List<Account>();
  18. for (Integer i = 0; i < numberOfAccounts; i++) {
  19. Account a = new Account();
  20. a.Name = 'Sample Account ' + (i+1) ;
  21.  
  22. acctlist.add(a);
  23. }
  24.  
  25. insert acctList;
  26.  
  27. List<Case> casesToInsert = new List<Case>();
  28.  
  29. for (Account a : acctList) {
  30. Case c = new Case();
  31. c.Status = 'New';
  32. c.Origin = 'New Account';
  33. c.AccountId = a.Id;
  34. c.Subject = 'New Case';
  35. c.Description = 'Follow Up';
  36. casesToInsert.add(c);
  37.  
  38. }
  39. insert casesToInsert;
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment