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
AgPrernaAgPrerna 

MAX(Date column) from related objects

I have a custom object- Object__c which has a look up to Account.
Object__c has a field Start_Date_Time__c.
I want to get records(Object__c) for each Account with Maximum value of Start_date_Time__c.

TIA
Best Answer chosen by AgPrerna
ShirishaShirisha (Salesforce Developers) 
Hi Prerna,

Greetings!

Please find the below sample SOQL query which you can use to query the Max date as below:
 
SELECT MAX(Start_date_Time__c), AccountId From Object group by AccountId​

Reference:https://developer.salesforce.com/forums/?id=9060G000000BfeYQAS

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri​​​​​​​

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi Prerna,

Greetings!

Please find the below sample SOQL query which you can use to query the Max date as below:
 
SELECT MAX(Start_date_Time__c), AccountId From Object group by AccountId​

Reference:https://developer.salesforce.com/forums/?id=9060G000000BfeYQAS

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri​​​​​​​
This was selected as the best answer
AgPrernaAgPrerna
Thank You for the quick response