I have a requirement to get the most recent task date on an account. When I use the following query, Salesforce does not return the correct answer. If I do the same query but on the task object, the result is correct.
SELECT ...
(
SELECT Id, ActivityDate, AccountId, WhatId, WhoId From Tasks
Where SalesLoft1__Call_Disposition__c = null
and (Not subject Like '%aircall%')
and (Not subject Like '%Marketing%')
and ActivityDate != null order by ActivityDate desc
) from Account where Id = '0015q000006T3y3AAC'
The result from this gives me an older task
When I query from the Task object, I get the correct task. Why would there be different results for the same account?
SELECT Id, subject, ActivityDate, AccountId, WhatId, WhoId From Task
Where accountid = '0015q000006T3y3AAC'
and SalesLoft1__Call_Disposition__c = null
and (Not subject Like '%aircall%')
and (Not subject Like '%Marketing%')
and ActivityDate != null order by ActivityDate desc Limit 1
Any ideas?