Skip to content

Instantly share code, notes, and snippets.

@niavesper
Last active March 17, 2021 18:54
Show Gist options
  • Save niavesper/323572e35fe245791bc3ea06e5a5e92b to your computer and use it in GitHub Desktop.
Save niavesper/323572e35fe245791bc3ea06e5a5e92b to your computer and use it in GitHub Desktop.
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];
}
}
@tugce
Copy link

tugce commented Mar 17, 2021

Wow awesome job @niavesper !! 🥇 I love that you've used SOQL For loops and also having return types on your methods are awesome.

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