You need to sign in to do that
Don't have an account?
ChickenOrBeef
How to include archived tasks in relationship SOQL query?
Hey everyone,
I have a SOQL query of the Contact object that includes a relationship query of the Tasks associated to the Contacts:
Right now the Task query doesn't seem to include archived tasks. I tried to include "ALL ROWS" somewhere in the Task query, but I kept getting errors. Then I tried adding "(IsArchived = TRUE OR IsArchived = FALSE)" to the query, but that didn't seem to include archived tasks when I tested the code.
Is there a way to include all Tasks (both archived and unarchived) in a Task relationship query? Am I doing it wrong?
Thanks,
Greg
I have a SOQL query of the Contact object that includes a relationship query of the Tasks associated to the Contacts:
FOR(Contact c1 : [SELECT Id,Last_Contacted__c (SELECT Id,Completed_Time_Formula__c FROM Tasks WHERE CreatedById != '005A0000004PQwZ' AND Completed_Time_Formula__c != NULL ORDER BY Completed_Time_Formula__c DESC LIMIT 1) FROM Contact WHERE Id In :contactsInTrigger]){ //code here }
Right now the Task query doesn't seem to include archived tasks. I tried to include "ALL ROWS" somewhere in the Task query, but I kept getting errors. Then I tried adding "(IsArchived = TRUE OR IsArchived = FALSE)" to the query, but that didn't seem to include archived tasks when I tested the code.
Is there a way to include all Tasks (both archived and unarchived) in a Task relationship query? Am I doing it wrong?
Thanks,
Greg
Here's some documentation from salesforce that tells you how to use ALL ROWS.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_query_all_rows.htm
So according to that documentation, the ALL ROWS should go at the end of the query. Try adding it at the end of your entire query like this:
All Answers
ALL ROWS should be the answer to your problem. What kind of errors are you getting, and where did you include ALL ROWS?
I tried adding ALL ROWS to the following four places:
Obviously I didn't try all four places at once, but those are the places where I tried. And before I could save my code I would see an error that says "expecting a right parentheses, found 'ALL'".
-Greg
Here's some documentation from salesforce that tells you how to use ALL ROWS.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_query_all_rows.htm
So according to that documentation, the ALL ROWS should go at the end of the query. Try adding it at the end of your entire query like this:
Or would putting the ALL ROWS at the very end apply it to both the Contact query AND the Task relationship query?
-Greg
Adding "ALL ROWS" to the end of the query ended up working! The Task relationship query retrieves the archived Tasks.
Thanks!
-Greg