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
WDCi NatWDCi Nat 

How can I exclude Recurring Activities Series records from a trigger?

We have a code that prevents us from closing a project if there are still open activities.
The trouble is that it picks up the "Not Started" Status update on the Recurring Tasks Series, even when the series has ended (end date has passed).

The Status of the actual Recurring Series record can't be updated: 
Recurring Task Error

The code is: public static void checkIncompleteTask(List<amc__Project__c> newList, Map<Id, amc__Project__c> oldMap) {
        List<Task> taskList = [SELECT Id, WhatId FROM Task WHERE WhatId IN: newList AND Status != 'Completed'];


Can anyone assist in excluding Recurring Series records from this? It doesn't appear as a separate RT, and isn't a reportable activity in itself.

Cheers, Nat
 
Best Answer chosen by WDCi Nat
RKSalesforceRKSalesforce
Hello Nat,
 
Please try adding one more condition on StartDate field of your task in your query.
List<Task> taskList = [SELECT Id, WhatId FROM Task WHERE WhatId IN: newList AND Status != 'Completed' AND StartDate <= TODAY];
Please let me know if helped.

Regards,
Ramakant

All Answers

RKSalesforceRKSalesforce
Hello Nat,
 
Please try adding one more condition on StartDate field of your task in your query.
List<Task> taskList = [SELECT Id, WhatId FROM Task WHERE WhatId IN: newList AND Status != 'Completed' AND StartDate <= TODAY];
Please let me know if helped.

Regards,
Ramakant
This was selected as the best answer
WDCi NatWDCi Nat
Thanks Ramakant, I'll pass that on to my internal team and see if that helps...I'll come back to you.  I appreciate you helping out!!