Skip to content

Instantly share code, notes, and snippets.

@JessWingerden
Created November 21, 2025 09:54
Show Gist options
  • Select an option

  • Save JessWingerden/bfd8ce711c422a905deba58c78110bd6 to your computer and use it in GitHub Desktop.

Select an option

Save JessWingerden/bfd8ce711c422a905deba58c78110bd6 to your computer and use it in GitHub Desktop.
Week 5 Homework
//1. Write a public method that calls the getCitiesForExpansion method to get a list of cities, then add
//another city to the list before printing it to the debug log.
//(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)
//JW: Adding additional city and printing to the debug list
public static void printOutCitiesForExpansionWithExtraCity() {
List<String> cities = getCitiesForExpansion();
cities.add('Gold Coast'); // add another city
System.debug('Here are the printed cities: ' + cities);
}
//2.Write a public method that calls the isTopSalesCity method and prints out the returned boolean to the debug log.
//You'll need to pass in a string variable that is a city name as the argument!
//JW: Adding a passed variable of the cityname
public static void printIsTopSalesCity(String cityName) {
Boolean result = isTopSalesCity(cityName);
System.debug(cityName + 'a top sales city? ' + result);
}
//3. BONUS!! If you've finished the first two, there's another public method below that will return the top 10 Accounts
//Write a public method that calls getTopTenAccounts. Can you loop through those accounts and change the name of those accounts with a DML Update?
//JW:Create a public method
public static void renameTopTenAccounts() {
List<Account> topAccounts = getTopTenAccounts();
// JW Assign a variable
Integer rank = 10;
//JW: Loop through the accounts to rename them and reduce the rank by 1 each loop.
for (Account acc : topAccounts) {
acc.Name = acc.Name + ' - TOP ' + rank;
rank--;
}
//JW: Update DML and debug
update topAccounts;
System.debug('Updated top 10 accounts names ' + topAccounts);
}
//4. BONUS!! Can you write a SOQL query that will return all opportunities for toptenAccounts based on Annual Revenue
//Hint: If you're stuck, look back a the code in ClassExercises, getOpenOppsForHotAccounts method
// Print your results in the debug log.
public static void getOppsForTopTenAccounts() {
// JW: Get the top 10 accounts.
List<Account> topAccounts = getTopTenAccounts();
// JW: Add the ID's of the account to a collection
Set<Id> accountIds = new Set<Id>();
for (Account acc : topAccounts) {
accountIds.add(acc.Id);
}
// JW: Query all opportunities for those accounts IDs
List<Opportunity> oppsForTopTen =
[SELECT Id, Name, StageName, Amount, AccountId
FROM Opportunity
WHERE AccountId IN :accountIds];
System.debug('Opportunities for top 10 accounts: ' + oppsForTopTen);
}
@vickihenry
Copy link

Nicely done this week! Love how you ranked the accounts when you were updating the name field. Keep it up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment