Created
November 7, 2025 08:00
-
-
Save JessWingerden/32a7f1e80c5790d94b4985a4eb0252b4 to your computer and use it in GitHub Desktop.
Week 3 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 WeekThreeHomework { | |
| public static void homeworkAssignmentMethod() { | |
| //Read through the setup below and then complete the code following the prompts. When you're done, make sure to compile (save) your work | |
| //Open Execute Anonymous in the Developer Console and execute your code by typing in: WeekThreeHomework.homeworkAssignmentMethod(); | |
| //Read through the debug statements to make sure you're done your work correctly. | |
| //************************************************************************************************************ | |
| // 1. Add two more whole numbers to this list using .add() | |
| List<Integer> numberList = new List<Integer>{0, 1, 1, 2, 3, 5, 8, 13, 21, 34}; | |
| numberList.add(55); | |
| numberList.add(89); | |
| //Checking our work: | |
| System.debug('This number should be 12: ' + numberList.size()); | |
| //************************************************************************************************************ | |
| // 2. Create a new Lead and insert it in the database. (If you're stuck, look back at the WeekThreeClassExercises class for an example of creating a new SObject Record) | |
| //You can give it any values you like, but remember that last name and Company are required fields (both are simple text fields.) | |
| //First lets create the object | |
| Lead newLead = new Lead(); | |
| //Lets assign some values | |
| newLead.FirstName = 'Santa'; | |
| newLead.LastName = 'Claus'; | |
| newLead.Company = 'Christmas Party Land'; | |
| newLead.Rating = 'Hot'; | |
| newLead.Description = 'Santa may or may not be coming to town - Need to lock it down'; | |
| //Now lets insert Santa into our Salesforce Databse | |
| insert newLead; | |
| //Checking our work: Outcome: DML executed was 1 | |
| System.debug('We should see One DML was executed: ' + Limits.getDMLRows()); | |
| } | |
| public static void forLoopsExercise() { | |
| //1. Let's review iterating over a list of stuff. How about Strings? | |
| List<String> myStringList = new List<String>{'red', 'yellow', 'green', 'blue'}; | |
| // using for loop syntax, loop over the list of strings, printing each one out to the debug log. | |
| for (string rainbowcolours: myStringList); | |
| {System.debug ('rainbow colours Loop:' + myStringList); | |
| } | |
| // 2. How about some SObjects? | |
| // I'll do the data setup here to create a list of contacts that all have a first name: | |
| Contact c1 = new Contact(FirstName='Sam'); | |
| Contact c2 = new Contact(FirstName='Diane'); | |
| Contact c3 = new Contact(FirstName='Coach'); | |
| List<Contact> myContacts = new List<Contact>{c1,c2,c3}; | |
| // Your turn! Using a an SObject for loop, print out the first name of each contact on a different line | |
| //hint, you will need to use dot notation! | |
| for(Contact nameVariable: myContacts) | |
| {System.debug('SOjects First Name: ' + nameVariable.FirstName); | |
| } | |
| //Bonus question to ponder: Do these contacts actually exist in our database? | |
| //What would it take to get them there? | |
| // insert myContacts; | |
| } | |
| } |
You would indent the System.debug line
Author
got it! thanks Vicki
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for (string rainbowcolours: myStringList) {
System.debug ('rainbow colours Loop:' + myStringList);
}
Sorry Github reformatted my code, so I'm copying it again here in plain text. Hopefully this will work!