Created
December 7, 2023 00:50
-
-
Save kamalpreet-rad/f02189a44326f9220522fd87cceab733 to your computer and use it in GitHub Desktop.
Week 2
This file contains hidden or 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
/*A method that includes a query for a List of contacts and returns the Account Name and Industry as well. | |
Use a loop to print the name of each Contact’s Account Name with System.debug.*/ | |
public class WeekTwoHomework | |
{ | |
Public Static void contactwithaccountindustry() | |
{ | |
List<Contact> ctlist = [Select id, FirstName,LastName, Department, Account.Name,Account.Industry from Contact]; | |
for(Contact c : ctlist) { | |
system.debug('Contact name with account and industry is '+c.FirstName+' '+c.LastName | |
+' '+c.Account.Industry+' '+c.Account.Name); | |
} | |
} | |
/*A method that includes a query for a list of Accounts AND | |
includes all their closed-won opportunities in a subquery. Use a loop to print out the name of each Account’s opportunity with System.debug*/ | |
Public static void OpportinitiesAreClosedOne() | |
{ | |
List<Account> listofaccount = [Select Name, | |
(select Name,Amount,StageName from Opportunities where StageName = 'Closed Won') | |
from Account | |
] ; | |
for( Account a: listofaccount) | |
{ | |
for(Opportunity opp: a.Opportunities) | |
{ | |
system.debug('Opportunity is '+ opp +'with Account'+ a.Name ); | |
} | |
system.debug('Name of Opportunity of an account is ' + a.Name); | |
} | |
} | |
/*A method that queries for Opportunity records that returns results in a map format.*/ | |
Public static void MapOpportunity() | |
{ | |
Map < ID, Opportunity > OppMap = New Map < ID,Opportunity > | |
([SELECT Id, Name, Amount FROM Opportunity WHERE Amount < 1000000]); | |
system.debug('The List of the Opportunities are' + OppMap); | |
} | |
/*An aggregate results query that returns an integer equal to the total number of open opportunities in your org*/ | |
Public Static Void AggregateResultOpp() | |
{ | |
List<AggregateResult> result = [Select count(Id), StageName from opportunity GROUP By StageName ]; | |
for(AggregateResult ar : result) | |
{ | |
System.debug('StageName: ' + ar.get('StageName')); | |
System.debug('Toatl Opportunities : '+ ar.get('total')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment