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
lisa.sturycz1.3890322391892622E12lisa.sturycz1.3890322391892622E12 

Display only most recent child record (by CreatedDate) in report

I am trying to create a report that only displays the most recently created child record of a custom child object on Opportunities, called Updates. As far as I can see, there is no filter option functionality that would allow me to select "Most Recent" Update record only to appear in report. Regardless of how long ago the most recent child record was created, I always want to show only that single record on the report. Does anyone have suggestions as to how to make this work "out of the box"?

If not, I was assuming I will need to create a custom field and use code. If a create a custom checkbox field titled Most Recent on the child object (Updates), does anyone have any suggestions for how to get a trigger to update this field on insert, update, & delete? Any time an Update is added, edited, or deleted all child Update records on this opportunity should have Most Recent unchecked, then only the one with the most recent date/time stamp should have the Most Recent field checked.

Thank you!
Sonam_SFDCSonam_SFDC
Can think of doing it this way:
Make this field as a checkbox - and create an (after insert after update) trigger on the child object to update this field such that this trigger will scan through all the existing related records of the particular Opportunity (using SOQL) its related to and filter the one which has a checkbox checked - 

if no child object is returned - check the box of the opportunity in trigger.new
If there is a child record - uncheck the box for this record and check the box for opportunity with trigger.new

Atul GuptaAtul Gupta
Hi Lisa,

Please check out the below link, this is a solution where you won't have to use code.

https://help.salesforce.com/apex/HTViewSolution?id=000002384&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000002384&language=en_US)


If you find my answers userful, please mark it as "Best Answer" right under the comment.
This will help if anyone else gets into the same issue. Thank you !!