Last active
December 9, 2025 10:15
-
-
Save JessWingerden/8f3228a4a2d0d85f82da3b43053e9ec1 to your computer and use it in GitHub Desktop.
Week 7 Homework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public with sharing class WeekSevenHomework { | |
| //Assignment: The following method is supposed to create the number of accounts specified in the argument that it takes. | |
| //Each Account should be named 'Sample Account #sampleNumber' where sample number is the count. So if you created 2 Accounts | |
| //one would be called 'Sample Account 1' and the other 'Sample Account 2' | |
| //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 | |
| //desription and subject of your choice. | |
| //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 | |
| //Look out for consistency and formatting too! (even if they don't break the code) | |
| //Add comments to describe what the code is doing. | |
| //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! | |
| public static void createSampleAccounts(Decimal numberOfAccounts) { | |
| List<Account> acctList = new List<Account>(); | |
| //JW: Changed the comparison operator to less than | |
| for (Integer i = 0; i < numberOfAccounts; i++) { | |
| Account a = new Account(); | |
| a.Name = 'Week 7 Homework New Account ' + (i + 1); | |
| //JW: The missing component was adding each loop into the acctList. | |
| acctList.add(a); | |
| } | |
| insert acctList; | |
| List<Case> casesToInsert = new List<Case>(); | |
| //JW: Removed additional con line 31 | |
| for (Account a: acctList) { | |
| Case c = new Case(); | |
| //JW: Changed the "" to ' | |
| c.Status = 'New'; | |
| c.Origin = 'New Account'; | |
| //JW: Had to add the a.id for the account Id | |
| c.AccountId = a.id; | |
| //JW: there is no = for line 38 | |
| c.Subject = 'New Case'; | |
| //JW: Description is misspelt and has 2 == and only needs 1 = | |
| c.Description = 'Follow Up'; | |
| casesToInsert.add(c); | |
| } | |
| //JW: Need to insert the cases | |
| insert casesToInsert; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment