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
Malik Butler 5Malik Butler 5 

Add multiple objects to class

I'm trying to add the opportunity and work order object to this apex class and I've tried everything but haven't had any luck. Any ideas?

public with sharing class CaseActivityController {
    
    public List<Task> lstTask {get;set;}
    
    public CaseActivityController(ApexPages.StandardController std) 
    {
        Id AccountId = std.getId(); //Get AccountId
        
        //Query on Task
        Map<Id, Case> mapIdToCase = new Map<Id,Case>([Select Id from Case WHERE AccountId =: AccountId]);
        
        //Query on Case Activity 
        lstTask = new List<Task>([SELECT CallType,Status,Subject,WhatId,ActivityDate,Description FROM Task WHERE WhatId IN: mapIdToCase.keySet() ORDER BY ActivityDate]);
        
    }

}
ANUTEJANUTEJ (Salesforce Developers) 
Hi Malik,

Can you elaborate on the scenario that you are implementing to check further?

Looking forward for your response.

Regards,
Anutej
Malik Butler 5Malik Butler 5
Hi Anutej, 

I need to be able to query tasks from accounts' related cases, opportunities, and work orders. This will display on the page layout so that users don't have to go to multiple pages.