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
Jeremy KrebbsJeremy Krebbs 

SOQL Query last modified date of lookup recored

I need to pull any Projects were the EDI_Result__c LastModifiedDate = today. I can't seem to figure out how to right my query. Below is what I have right now. EDI_Result__c is a look up field. 

SELECT EDI_Result__c FROM Project__c WHERE LastModifiedDate = today
Best Answer chosen by Jeremy Krebbs
Lalit Mistry 21Lalit Mistry 21
Hi Jeremy,
If you are looking to retrieve all projects modified today then below SOQL should work
SELECT ID, EDI_Result__c FROM Project__c WHERE LastModifiedDate = TODAY

If you are looking to retrieve all projects where their related lookup record (EDI_Result__c) is modified today then use below SOQL
SELECT EDI_Result__c FROM Project__c WHERE EDI_Result__r.LastModifiedDate = TODAY

Let us know if this helps.
 

All Answers

Lalit Mistry 21Lalit Mistry 21
Hi Jeremy,
If you are looking to retrieve all projects modified today then below SOQL should work
SELECT ID, EDI_Result__c FROM Project__c WHERE LastModifiedDate = TODAY

If you are looking to retrieve all projects where their related lookup record (EDI_Result__c) is modified today then use below SOQL
SELECT EDI_Result__c FROM Project__c WHERE EDI_Result__r.LastModifiedDate = TODAY

Let us know if this helps.
 
This was selected as the best answer
Wagner BaldinWagner Baldin
That was exctly what I was looking for, the last modified date. But, if want a LastModofiedDate > 2022-01-05 for example? How to write the acceptable format?
The Error says: value of filter criterion for field 'LastModifiedDate' must be of type dateTime and should not be enclosed in quotes.
Sandeep R 15Sandeep R 15
Hi Wagner,
convert youre string value to a date use below as an example.
datetime d = date.valueOf('2023-01-30T00:00:00Z');

SELECT ID, EDI_Result__c FROM Project__c WHERE LastModifiedDate = :d