I have been developing a scheduled class that changes the BMCServiceDesk__FKStatus__c
to "Closed" on BMCServiceDesk__Incident__c
records that have had a BMCServiceDesk__FKStatus__c
of "Resolved" for 5 days or more.
A new requirement states that BMCServiceDesk__Incident__c
records should only have the status changed in this way if the all associated child BMCServiceDesk__Task__c
records have a BMCServiceDesk__FKStatus__c
of "Resolved".
So I need to change my query to only pull through BMCServiceDesk__Incident__c
records with a BMCServiceDesk__FKStatus__c
of "Resolved" where all associated BMCServiceDesk__Task__c
records have an BMCServiceDesk__FKStatus__c
equal to "Resolved". I don't understand how I can do this? Below is my code showing how far I've got.
{
List<BMCServiceDesk__Status__c> ClosedStatus = [SELECT Id FROM BMCServiceDesk__Status__c WHERE Name = 'Closed'];
List<BMCServiceDesk__Incident__c> listIncident = [SELECT Id FROM BMCServiceDesk__Incident__c
WHERE BMCServiceDesk__Status_ID__c = 'Resolved'
AND (BMCServiceDesk__StatusChangeDate__c = N_DAYS_AGO:5
OR BMCServiceDesk__StatusChangeDate__c = N_DAYS_AGO:6
OR BMCServiceDesk__StatusChangeDate__c = N_DAYS_AGO:7) LIMIT 100];
List<BMCServiceDesk__Task__c> listTask = [SELECT Id FROM BMCServiceDesk__Task__c
WHERE BMCServiceDesk__FKIncident__c : listIncident]
for(BMCServiceDesk__Incident__c up: listIncident)
{
up.BMCServiceDesk__FKStatus__c = ClosedStatus[0].ID;
}
update listIncident;
}
}