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
Chenna4a2Chenna4a2 

Urgent Help on updating Date (Logical question )

Hi,

 

I am having 2 objects student & child

 

Student has start Date field.

 

Child object has lookup to student object & start date field.

 

IF i associate child with student it need to pull the start date on  student &  shld populate on  child. ( working fine bcoz we r performing some action i.e updatig the child record)

 

Question : IF i change start date field on Student object it shld automatically populate Start date on Child without any action performing on child record ??

 

We can't create formula field on child bcoz they will enter manually..

 

Please help ????

 

Thanks,

Chenna

GlynAGlynA

Chenna,

 

The easy way to do this is to create a formula field on the child object that is equal to the start date on the student object.  But, you say you can't do this because the start date field on the child object must be editable.  So, the only way to do this is with triggers.

 

The trigger on the child object should run before insert and before update, and it will query the related student record and populate the start date field.

 

The trigger on the student object should run after update.  (No need to do after insert, as there won't be any child records yet.)  It will query all child records related to the student record and update the field.

 

There are two things to think about here.  The first is to write the trigger so that they are bulk-safe.  You should not put any queries or dml statements inside of a loop.  This will require the judicious use of maps.

 

The second is what happens when someone edits the start date field on a child record.  When they save the record, the trigger will run and update the start date field with the value that's in the student record - thereby overwriting the value that the user entered.  How does the trigger know not to overwrite their start date?  And if they subsequently update the child record again for a different reason, how does the trigger know not to update the start date then?

 

I will be happy to offer some code if you need it.  I'd like to know how you will answer my two questions above.  Thanks!

 

-Glyn