Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. public with sharing class WeekTwoHomework {
  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: WeekTwoHomework.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. numberList.add(2);
  14. numberList.add(4);
  15.  
  16.  
  17.  
  18. //Checking our work: debug evaluates to 12 because you started with 10 numbers and added 2.
  19. system.debug('This number should be 12: ' +numberList.size());
  20.  
  21.  
  22.  
  23. //************************************************************************************************************
  24. // 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)
  25. //You can give it any values you like, but remember that last name and Company are required fields (both are simple text fields.)
  26. Lead L = new Lead();
  27.  
  28. L.FirstName = 'Mickey'; //can comment on same code line!
  29. L.LastName = 'Mouse';
  30. L.Company = 'Disney World';
  31. 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?
  32. L.City = 'Orlando';
  33. L.State = 'FL';
  34.  
  35.  
  36. //Checking our work:
  37. system.debug('We should see One DML was executed: '+ Limits.getDMLRows());
  38.  
  39.  
  40. //************************************************************************************************************
  41. //3. For the loop that is commented out below, update the while condition by replacing the ?? so that the loop runs 5 times
  42. //delete the slashes so that the loop is no longer commented out and compile the class.
  43.  
  44. //Can you add a debug statement to print out the counter value every time it runs through the loop?
  45.  
  46.  
  47. Integer counter = 0;
  48.  
  49. while (counter < 5) { //from position 0,1,2,3,4 position 5<5 is Falso so counter stops incrementing and the loop is done!
  50. counter++; //without this line to increment counter, we'd have an infinite loop!
  51. //}
  52.  
  53. System.debug('Done with the loop, it ran: ' + counter + ' times.');
  54.  
  55. }//added due to error, may have deleted one by accident - or a teachable moment!
  56.  
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement