Guest User

Untitled

a guest
Mar 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. public with sharing class WeekThreeHomework {
  2.  
  3. //Let's practice calling different methods by writing our very own methods. You will write and save methods in the space below
  4. //that call the existing methods you see already written here. Ready? Let's Go!
  5.  
  6.  
  7. //Sample: Here is a public method that calls the getfavoriteColorsMethod below and prints the results to our debug log
  8. public static void printOutFavoriteColorsDemo() {
  9. List<String> favoriteColors = getFavoriteColors();
  10. System.debug('Here are the favorite colors: ' + favoriteColors);
  11. }
  12.  
  13.  
  14. //1. Write a public method that calls the getFavoriteColors method to get a list of favorite colors, then add
  15. //another color to the list before printing it to the debug log.
  16. //(see the sample above for an example of calling that method-You can even start by copying and pasting that method here, renaming and modifying it)
  17.  
  18. public static void enhancedFavoriteColoursList() {
  19. List<String> favoriteColors = getFavoriteColors();
  20. favoriteColors.add('navy');
  21. System.debug('Here are the favorite colors: ' + favoriteColors);
  22.  
  23. }
  24. //2.Write a public method that calls the amIFeelingGood and prints out the returned string to the debug log.
  25. //You'll need to pass in a boolean variable as the argument!
  26. public static String doIFeelGood(Boolean checkMood) {
  27. String todaysMood = amIFeelingGood(checkMood);
  28. return todaysMood;
  29. }
  30. /* WeekThreeHomework.doIFeelGood(true);
  31. System.debug(todaysMood);
  32. */
  33. //3. BONUS!! If you've finished the first two, there's another private method below that will return the top 10 Accounts
  34. //Write a public method that calls getTopTenAccounts. Can you loop through those accounts and change the name of those accounts with a DML Update?
  35. public static void addTopAccounts(){
  36. List <Account> topTenAccounts = getTopTenAccounts();
  37. For (Account acc: topTenAccounts) {
  38. acc.Name = acc.name + '- updateByCristina';
  39. System.debug('Top Account: '+acc.Name);
  40. }
  41. update topTenAccounts;
  42. }
  43.  
  44.  
  45.  
  46. //no arguments taken, will return the same thing every time
  47. private static List<String> getFavoriteColors() {
  48. List<String> colorResponses = new List<String>();
  49.  
  50. colorResponses.add('Red');
  51. colorResponses.add('Yellow');
  52. colorResponses.add('Blue');
  53.  
  54. //this is the line that sends our final product out to whatever method called this one
  55. return colorResponses;
  56. }
  57.  
  58.  
  59. //takes a boolean argument and returns a string, based on that input
  60. private static String amIFeelingGood(Boolean feelingGood) {
  61. if (feelingGood == true) {
  62. return 'Heck Yes! You are RAD!';
  63. } else {
  64. return 'Sorry to hear it. Nothing like writing some code to cheer you up!!';
  65. }
  66. }
  67.  
  68.  
  69. //This method will give you the top ten account records, based on Annual Revenue
  70. //You don't need to know exactly how the method you're calling works, we'll cover SOQL queries later, but take a look and you'll likely get the gist
  71. //What's important to know is that when called it will return a list of top Accounts based on revenue, returning no more than 10.
  72. private static List<Account> getTopTenAccounts() {
  73.  
  74. List<Account> topAccounts =
  75. [SELECT Id, Name, AnnualRevenue FROM Account WHERE AnnualRevenue != NULL AND AnnualRevenue != 0
  76. ORDER BY AnnualRevenue DESC LIMIT 10];
  77. return topAccounts;
  78. }
  79.  
  80.  
  81. }
Add Comment
Please, Sign In to add comment