function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saumya SumanSaumya Suman 

Hii, help me to write this code

Write an Apex code to find the number of tasks Assigned to a Particular contact related to an Opportunity record.
DarthMaulDarthMaul
This is pseudo code for the same,
map<string,string> contactOppMap;
// extract contact id and store with opportunity i n a map for refernce
for( Opportunityt this : [ select id , contactid from Opportunity]){
contactOppMap.put( this.id , this.contact) ;
}
map<string,integer> contactTaskMap;
// now loop over the contacts and put the size of the tasks in another map
for( COntact con : [ select id ,( select id from tasks) from contact where ide in : contactOppMap.keySet() ]){
contactTaskMap.put(con.id,con.tasks==null?0:con.tasks.size()) ;
}
// now link the two maps and yer good to go.