Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. public with sharing class WeekThreeHomework {
  2.  
  3.  
  4. public static void homeworkAssignmentMethod() {
  5. //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
  6. //Open Execute Anonymous in the Developer Console and execute your code by typing in: WeekThreeHomework.homeworkAssignmentMethod();
  7. //Read through the debug statements to make sure you're done your work correctly.
  8.  
  9. //************************************************************************************************************
  10.  
  11. // 1. Add two more whole numbers to this list using .add()
  12. List<Integer> numberList = new List<Integer>{ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 };
  13.  
  14. numberList.add(55);
  15. numberList.add(89);
  16.  
  17.  
  18. //Checking our work:
  19. System.debug('This number should be 12: ' + numberList.size());
  20.  
  21. //************************************************************************************************************
  22. // 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)
  23. //You can give it any values you like, but remember that last name and Company are required fields (both are simple text fields.)
  24.  
  25. Lead l = new Lead();
  26.  
  27. l.FirstName = 'Test';
  28. l.LastName = 'Testerson';
  29. l.Company = 'Lead Inc.';
  30. l.Email = 'lead@test.com';
  31.  
  32.  
  33. // insert the lead
  34. insert l;
  35.  
  36.  
  37. //Checking our work:
  38. System.debug('We should see One DML was executed: ' + Limits.getDMLRows());
  39.  
  40.  
  41. //************************************************************************************************************
  42. //3. For the loop that is commented out below, update the while condition by replacing the ?? so that the loop runs 5 times
  43. //delete the slashes so that the loop is no longer commented out and compile the class.
  44.  
  45. //Can you add a debug statement to print out the counter value every time it runs through the loop?
  46.  
  47.  
  48. Integer counter = 0;
  49.  
  50. while (counter < 5) {
  51. counter++; //without this line to increment counter, we'd have an infinite loop!
  52. //}
  53.  
  54. System.debug('Done with the loop, it ran: ' + counter + ' times.');
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement