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
chris_centrachris_centra 

SOQL for recurring Task?

Hello.  Years ago I wrote some Apex code (batch process) which determines the "most recent Task" on a Contact.  It queries the TaskRelation object for each Contact, does some filtering, and chooses the mostly recently completed Task.  No problem - until recently the Users started creating recurring Tasks.  My code doesn't see them.  I did some digging and i found the following:
1) if i run a simple soql query on a NON-recurring Task, one record is returned (Select Id From Task WHERE Id = '00TE0000018y793')
BUT...
2) if i update that Task, setting the RepeatThisTask (RecurrenceRegeneratedType) and RecurrenceInterval fields to non-null values - and i run the exact same query, no record is returned. 

What is happening here?  Does the record find its way to a different object, or do i have to run the query differently?  (FWIW, i notice that with a recurring Task, the TaskRelation record exists - and it points to the correct TaskId, but if i try to pull values from that related Task via SOQL, i get nothing...)

thanks very much for your time.
chris
Best Answer chosen by chris_centra
Marty C.Marty C.
Hello, Chris, I tried to replicate the problem you described in my org, using API 32.0, and I could not get the same behavior to surface. In my org, updating an existing, non-recurring task so that it has RecurrenceRegeneratedType and RecurrenceInterval values works as expected. Querying for the same task by Task ID gives me the expected record.

In your case, perhaps you have a trigger or something else in your org or your code that is automatically deleting the non-recurring task? Can you confirm in the actual Salesforce UI whether you can still see the task? And if so, whether its Task ID has changed?

All Answers

Marty C.Marty C.
Hello, Chris, I tried to replicate the problem you described in my org, using API 32.0, and I could not get the same behavior to surface. In my org, updating an existing, non-recurring task so that it has RecurrenceRegeneratedType and RecurrenceInterval values works as expected. Querying for the same task by Task ID gives me the expected record.

In your case, perhaps you have a trigger or something else in your org or your code that is automatically deleting the non-recurring task? Can you confirm in the actual Salesforce UI whether you can still see the task? And if so, whether its Task ID has changed?
This was selected as the best answer
chris_centrachris_centra
Hello Marty - thanks for your reply.  I confirmed that the record's Id did not change - but I changed my API version per your email above (I was originally working in eclipse, which is still API 27) - and then it worked as you describe.  Thanks so much for your help!
chris
 
Marty C.Marty C.
Thanks for the update, Chris. I'm glad the fix was as simple as an API version change. Digging through the release notes, it appears that the RecurrenceRegeneratedType field was introduced in Spring '14[1], which corresponds to API 30.0.

[1]: Spring '14 (https://help.salesforce.com/help/pdfs/en/salesforce_spring14_release_notes.pdf)