I have two queries that are similar except there's a few differences between them. I was wondering if there's a way to optimize this, by querying this once and still do what I want with my code.
The Code
List<Task__C> tasksToDelete = [SELECT ID, Case__c FROM Task__C
WHERE ID NOT IN (SELECT Project_Task__c FROM Time__c
WHERE Project_Task__r.Case__c in :oldCaseIDList) AND Case__c in: oldCaseIDList];
List<Task__c> keepCases = [SELECT ID, Case__c FROM Task__c
WHERE ID IN (SELECT Project_Task__c FROM Time__c
WHERE Project_Task__r.Case__c in :oldCaseIDList)] ;
for (Task__c: task: keepCases) {
// do something with the cases associated to the tasks
}
// do something with tasksToDelete