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
Sudiptaa GhoshSudiptaa Ghosh 

inner query in soql

SELECT Id, (SELECT Name from Contacts WHERE CreatedDate > YESTERDAY or LastModifiedDate >  YESTERDAY) from Account where CreatedDate > YESTERDAY or LastModifiedDate > YESTERDAY

I want to get all records from Account and Contact where created date or last modified date is within a certain range. If there are changes in Contact , I want those records , even there are no changes in Account Object 

But this query will not fetch any records if there are any change in only Contact and no change in Account. How can I possibly do that.

Can anybody please help.

 

Raghu NaniRaghu Nani
So you have to write seperate Querie for Conatct irrespective of account
Chandu007Chandu007
I think it's better to use Report by using filters on Account & Contact objects to get the records.
Sudiptaa GhoshSudiptaa Ghosh

Chandu007,

how can I do that , could you pls elaborate.
 

Ajay K DubediAjay K Dubedi
Hi Sudiptaa,

You can use the below query: 

I have made some changes in your query and I also implemented in my org and it's working fine and I am getting results. 
I have also attached an image of the result below. Please try this query.

SELECT Id, (SELECT Name from Contacts WHERE CreatedDate >= today or LastModifiedDate >=  today ) from Account where CreatedDate >= today or LastModifiedDate >= today

User-added image


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com