Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. public with sharing class WeekFourHomework {
  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 getCitiesForExpansion below and prints the results to our debug log
  8. public static void printOutCitiesForExpansionDemo() {
  9. //The code on the left of the equals sign instantiates a list of Strings, the code on the right side calls our method and returns a list of cities
  10. //the equals sign assigns the returned value, to the list we created
  11. List<String> cities = getCitiesForExpansion();
  12. System.debug('Here are the cities: ' + cities);
  13. }
  14.  
  15.  
  16. //1. Write a public method that calls the getCitiesForExpansion method to get a list of cities, then add
  17. //another city to the list before printing it to the debug log.
  18. //(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)
  19.  
  20. public static void findOutCitiesForExpansionDemo() {
  21. //The code on the left of the equals sign instantiates a list of Strings, the code on the right side calls our method and returns a list of cities
  22. //the equals sign assigns the returned value, to the list we created
  23. List<String> kEcities = getCitiesForExpansion();
  24. kEcities.add('NYC');
  25. System.debug('Here are the cities: ' + kEcities);
  26. }
  27.  
  28.  
  29. //2.Write a public method that calls the isTopSalesCity method and prints out the returned boolean to the debug log.
  30. //You'll need to pass in a string variable that is a city name as the argument!
  31. public static void verifyTopSalesCity(){
  32. String topSalesCity = 'Houston';
  33. Boolean isTopCity = isTopSalesCity('inspectCity');
  34. System.debug(topSalesCity+ 'Is the top sales city ' + isTopCity);
  35. }
  36.  
  37.  
  38. //3. BONUS!! If you've finished the first two, there's another public method below that will return the top 10 Accounts
  39. //Write a public method that calls getTopTenAccounts. Can you loop through those accounts and change the name of those accounts with a DML Update?
  40. public static void changeAccounts(String addName){
  41. List<Account> topTenAccounts = getTopTenAccounts();
  42. System.debug('Top Ten Accounts: '+ topTenAccounts);
  43. for(Account topAcct: topTenAccounts){
  44. topAcct.Name = topAcct.Name + ' ' + addName;
  45. }
  46. Update topTenAccounts;
  47. System.debug('Top Ten Accounts: ' + topTenAccounts);
  48. }
  49.  
  50. //no arguments taken, will return the same thing every time
  51. public static List<String> getCitiesForExpansion() {
  52. List<String> cities = new List<String>();
  53.  
  54. cities.add('Tokyo');
  55. cities.add('Melbourne');
  56. cities.add('Portland');
  57.  
  58. //this is the line that sends our final product out to whatever method called this one
  59. return cities;
  60. }
  61.  
  62.  
  63. //takes a string argument and returns a boolean, based on that input
  64. public static Boolean isTopSalesCity (String cityName) {
  65. if (cityName=='Seattle' || cityName=='Los Angeles' || cityName=='Portland') {
  66. return true;
  67. } else {
  68. return false;
  69. }
  70. }
  71.  
  72.  
  73. //This method will give you the top ten account records, based on Annual Revenue
  74. //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
  75. //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.
  76. public static List<Account> getTopTenAccounts() {
  77.  
  78. List<Account> topAccounts =
  79. [SELECT Id, Name, AnnualRevenue FROM Account WHERE AnnualRevenue != NULL AND AnnualRevenue != 0
  80. ORDER BY AnnualRevenue DESC LIMIT 10];
  81. return topAccounts;
  82. }
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement