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
NANCY1NANCY1 

Set the master field value from multiple detail records??

Hi ,

 

I have a master object with tthe date field Test__c. And i have multiple detail records associated with the master record.

Among all the detail record i need to catch the largest date and copy it to the master field.

 

Please suggest how can i achieve this with the help of trigger??

 

myforcedotcommyforcedotcom

You can do this using a trigger, but you will want to do this as an afterInsert, afterUpdate on the Detail record.

I have outlined the steps below for the trigger.

 

 

  1. retrieve all the details records for the same master record into a List
  2. iterate through the list to get the largest date
  3. retrieve the master record
  4. check to see if the detail largest date is larger than the master record date. if it is set the date on the master record and update the master. if not do nothing.

 

 

 

code the cloud