Last active
March 17, 2021 18:54
-
-
Save niavesper/323572e35fe245791bc3ea06e5a5e92b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WeekTwoHomework { | |
// method (a) | |
public static void showAccNames(){ | |
integer i=0; | |
for (Contact c : [SELECT Id, Account.Name, Account.Industry FROM Contact]){ | |
i++; | |
System.debug ('Name of Account # ' + i + ' is ' + c.Account.Name); | |
} | |
} | |
// method (b) | |
public static void showContNames(){ | |
for(Account a : [SELECT Id, Name, (SELECT Name FROM Opportunities WHERE StageName = 'Closed Won') FROM Account]){ | |
List<Opportunity> oppsList = a.opportunities; | |
for (Opportunity opp : oppsList){ | |
System.debug('Name of Opportunity for account' + a.Name + ' is ' + opp.Name ); | |
} | |
} | |
} | |
// method (c) | |
public static Map<Id, Opportunity> returnOppMap(){ | |
return new Map <Id, Opportunity>([SELECT Id From Opportunity]); | |
} | |
// method (d) | |
public static integer showNumOpenOpps(){ | |
return [SELECT COUNT() FROM Opportunity WHERE isClosed = false]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow awesome job @niavesper !! 🥇 I love that you've used SOQL For loops and also having return types on your methods are awesome.