Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class WeekTwoHomework {
- public static void homeworkAssignmentMethod () {
- //Read through the set-up 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: WeekTwoHomework.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(2);
- numberList.add(4);
- //Checking our work: debug evaluates to 12 because you started with 10 numbers and added 2.
- 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 WeekTwoClassExercises 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.)
- Lead L = new Lead();
- L.FirstName = 'Mickey'; //can comment on same code line!
- L.LastName = 'Mouse';
- L.Company = 'Disney World';
- L.Status = 'New Lead'; //What if you declare a new value that does not exist in your picklist? Is it like DataLoader & will insert the value?
- L.City = 'Orlando';
- L.State = 'FL';
- //Checking our work:
- system.debug('We should see One DML was executed: '+ Limits.getDMLRows());
- //************************************************************************************************************
- //3. For the loop that is commented out below, update the while condition by replacing the ?? so that the loop runs 5 times
- //delete the slashes so that the loop is no longer commented out and compile the class.
- //Can you add a debug statement to print out the counter value every time it runs through the loop?
- Integer counter = 0;
- while (counter < 5) { //from position 0,1,2,3,4 position 5<5 is Falso so counter stops incrementing and the loop is done!
- counter++; //without this line to increment counter, we'd have an infinite loop!
- //}
- System.debug('Done with the loop, it ran: ' + counter + ' times.');
- }//added due to error, may have deleted one by accident - or a teachable moment!
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement