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
jwalshjwalsh 

Query for Task by known id returns no result

Hello all,


Seeing some odd behaviour during some data cleanup.  We had a Contact c on the wrong Account a1 with an OpportunityContactRole ocr1 on Opportunity o1, o1.accountid=a1.id.
C was actually supposed to be attached to Account a2, with Opportunity o2.accountid = a2.id.  C was edited to move over to a2, ie c.accountid = a2.id.
After this move, all of the tasks on o1 associated with c stayed put on o1.  I wrote a small script to scrape o1's tasks, detect what needed to be moved over, and moved them (ie whatid=o2.id).  This worked fine for most of the tasks.
However, there are some tasks left over with whoid=c.id and whatid=o1.id.  When I go to o1's detail page in the sfdc ui, they still show in the related activities list.

 

The odd part:
Querying for tasks (using force.com explorer) related to o1 doesn't return the problem task that should have moved but didn't.   Further, I tried to query for pt's info in Force.com explorer:  select id, whoid, whatid, subject from task where id='00T8000001JEj18'.  Much to my surprise, this query returned no result.

 

Question:
Under what circumstance will the front end show you an object, but that object cannot be queried from the database?  As a further note, I also queried "Event" for the same id and get nothing; I'm slightly confused by the Task/Event/Activity dual-/tri-ality so I figured I'd give it a shot; however the detail page for the object I'm looking for has the Task layout and says "Task" in the top of the detail page.


Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

jwalsh,

 

Tasks and Events are tricky objects in Salesforce data model because they are one of the few "Polymorphic" objects in the system, allowing them to be linked to different types of objects based on the WhatId. They further are aggregated at the UI / Setup level as "Activities", but that is just a grouping for the two distinct objects Task and Event.

 

In additoin, Tasks and Events can be Archived if they are older than 365 days old. If an activity is archived, it will not show up in a standard SOQL query. You'll need to add the 'ALL ROWS' modifier to a SOQL query to retrieve those types of Tasks and Events.

 

Try adding the ALL ROWS modifier to your SOQL and see if that works.

 

 

All Answers

Cory CowgillCory Cowgill

jwalsh,

 

Tasks and Events are tricky objects in Salesforce data model because they are one of the few "Polymorphic" objects in the system, allowing them to be linked to different types of objects based on the WhatId. They further are aggregated at the UI / Setup level as "Activities", but that is just a grouping for the two distinct objects Task and Event.

 

In additoin, Tasks and Events can be Archived if they are older than 365 days old. If an activity is archived, it will not show up in a standard SOQL query. You'll need to add the 'ALL ROWS' modifier to a SOQL query to retrieve those types of Tasks and Events.

 

Try adding the ALL ROWS modifier to your SOQL and see if that works.

 

 

This was selected as the best answer
jwalshjwalsh

Thanks so much Cory, you hit the nail on the head.  In this case the objects that weren't behaving were all over a year old; didn't pick that up by casual observation.