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
Suraj_BahaleSuraj_Bahale 

Hello, How to write SOQL query to get only Updated and Newly created Records using LastModifiedDate field.

i want to get only Updated and newly created records from custom object... How to get only Updated and newly created records using SOQL query?
Best Answer chosen by Suraj_Bahale
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Suraj,
Try this Query.Please change Date according to your requirements
select id from contact where LastModifiedDate > 2019-12-03T00:00:00Z  OR CreatedDate > 2019-12-03T00:00:00Z

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards

All Answers

Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Suraj,
Try this Query.Please change Date according to your requirements
select id from contact where LastModifiedDate > 2019-12-03T00:00:00Z  OR CreatedDate > 2019-12-03T00:00:00Z

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards
This was selected as the best answer
Suraj_BahaleSuraj_Bahale
Thank You, It Worked.

But I want to convert LastModifiedDate  in Milliseconds so i can use it as a timestamp
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
you can covert datetime to millisecond  by using millisecond() method of datetime class.
please refer below link which might help you in this
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_datetime.htm

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards