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
v1.323870375512286E12v1.323870375512286E12 

takin the value from one of the child custom object field and showing in Account object

Hii,

 

can anyone tell me the code for the below requirement

 

 

 salary object is a custom object. Salary has look up to Account object. Salary object has a field "Payment date" which is in text data type. Account has a field "Last date of payment" which is of "Date" type. we can add many salary record to account in related list. but requirement is the field "Last date of payment" in account will get the value from child salary "Payment date" field and display the recent ddte among all salary records.

Navatar_DbSupNavatar_DbSup

Hi,

 

You have to write a trigger for this. You have to write the trigger on child object which will update the parent object field.

 

Try the below code as reference:

 

 

Trigger ChildObject on Salary__c(after insert)

{

Account ac=[select id, Last_dat_ of_payment__c from account where id=:trigger.new[0].account__c];

Ac. Last_date_of_payment__c =date.valueof( trigger.new[0]. Payment_date__c);

Update ac;

}

Modify the same for update as per your requirement.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

v1.323870375512286E12v1.323870375512286E12

Hi..

 thanks for ur reply..but this is not working and the child field value is not taking. i mean it is showing error while assigning the child field value to parent field.

v1.323870375512286E12v1.323870375512286E12

hello,

 

One more requirement i have. it should filter only "Grade one" record type of child object so how to achive it. If i ll do same for 2 fields..shall i need map