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
Surya Teja PothureddySurya Teja Pothureddy 

Need help on a SOQL

Hi friends, 

Can someone help me in writing a query where i need to get only those contacts who have one or more activity history records? I can up with a solution like this : 

select id, first_activity_date__c,LastActivityDate, (select id, createddate from activityhistories) from contact where first_activity_date__c = null and LastActivityDate != null

But even the above returns some records without activity histories. We cannot put a sub query as a filter as it is not allowing for the same. Help is appreciated. Thanks.
Balayesu ChilakalapudiBalayesu Chilakalapudi

Try like this,
select id, firstname, (select id from Tasks where status='Completed') from contact
Let me know if it helps