Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 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. numberList.add(24);
  14. numberList.add(30);
  15.  
  16. //Checking our work:
  17. System.debug('This number should be 12: ' + numberList.size());
  18.  
  19. //************************************************************************************************************
  20. // 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)
  21. //You can give it any values you like, but remember that last name and Company are required fields (both are simple text fields.)
  22. Lead l = new Lead();
  23. l.FirstName = 'Allison';
  24. l.LastName = 'Vang';
  25. l.Company = 'The 4A Foundation';
  26. l.City = 'Fresno';
  27. l.State = 'CA';
  28.  
  29. insert l;
  30.  
  31. //Checking our work:
  32. System.debug('We should see One DML was executed: ' + Limits.getDMLRows());
  33.  
  34.  
  35. //************************************************************************************************************
  36. //3. For the loop that is commented out below, update the while condition by replacing the ?? so that the loop runs 5 times
  37. //delete the slashes so that the loop is no longer commented out and compile the class.
  38.  
  39. //Can you add a debug statement to print out the counter value every time it runs through the loop?
  40.  
  41.  
  42. Integer counter = 0;
  43.  
  44. List<Lead> newLeads = new List<Lead>();
  45.  
  46. while (counter < 5) {
  47. Lead a = new Lead();
  48. a.LastName = 'Xiong';
  49. a.Company = 'New Prospect' + counter;
  50. newLeads.add(a);
  51. System.debug('Counter value '+ counter );
  52. counter++; //without this line to increment counter, we'd have an infinite loop!
  53. }
  54.  
  55. System.debug('Done with the loop, it ran: ' + counter + ' times.');
  56.  
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement