Created
May 6, 2025 14:51
-
-
Save abbiebauer37/7b386b99879fcbb6ca1e528a8cd8b334 to your computer and use it in GitHub Desktop.
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(Integer numberOfAccounts) { //changed the parameter from decimal to integer | |
List<Account> acctList = new List<Account>(); | |
for (Integer i = 0; i < numberOfAccounts; i++) { //removed = from <= to ensure we only create up to the number of account specified | |
Account a = new Account(); | |
a.Name = 'Sample Account ' + i; //changed string to Sample Account and added the number of accounts | |
acctList.add(a); //added the new account(s) | |
} | |
insert acctList; | |
System.debug('How many accounts did we add? ' + acctList.size()); | |
List<Case> casesToInsert = new List<Case>(); | |
for (Account a: acctList) { //removed the extra c from acctList | |
Case c = new Case(); | |
c.Status = 'New'; // corrected the "paratheses" to a 'single quote' for a string | |
c.Origin = 'New Account'; //added ; | |
c.AccountId = a.Id; //added .Id to a | |
c.Subject = 'New Case'; // added = to assign Case Subject to 'New Case' | |
c.Description = 'Follow Up'; // Corrected the spelling of Description (was descritpion) and removed the == to be = for assignment | |
casesToInsert.add(c); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's really good Abbie!
Also you found the parameter to the method should be an integer, you're only the second person so far who found that sneaky mistake, so well done!
Just a couple of comments: