Last active
October 6, 2020 18:06
-
-
Save asmitakhare/69e0cca16d26249109abd66a1f5cb5f8 to your computer and use it in GitHub Desktop.
Asmita WeekEightHomework.apxc
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 WeekEightHomework { | |
//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) { // the numberOfAccounts should be Integer and not decimal | |
system.debug('Number of Accounts ' +numberOfAccounts); | |
// get the List of Accounts | |
List<Account> acctList = new List<Account>(); | |
//loop through each account and get the count of loop each time by using integer | |
for (Integer i = 0; i < numberOfAccounts; i++) { // taking account from 0 to numberOfAccounts - 1 | |
system.debug('check the value of i ' + i);//added space | |
// we are creating a new account and adding that to the account list | |
Account a = new Account(); | |
a.Name = 'Sample Account ' + (i+1);// adding i+1 | |
acctList.add(a); | |
} | |
system.debug('number of accounts inserted ' +acctList.size()); | |
insert acctList; | |
//we will create a case whenever a new account is inserted | |
List<Case> casesToInsert = new List<Case>(); | |
for (Account a: acctList) { | |
Case c = new Case(); | |
c.Status = 'New'; | |
c.Origin = 'New Account'; | |
c.AccountId = a.Id; | |
c.Subject = 'New Case'; | |
c.Description = 'Follow Up'; | |
casesToInsert.add(c); | |
} | |
//now check how many cases has inserted in total | |
System.debug('How many cases we are inserting? ' + casesToInsert.size()); | |
insert casesToInsert; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Pat