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
Jessica PastorJessica Pastor 

Cross object field update trigger

Hi - I do not have much Apex experience so please forgive me in advance.

I would like to have a cross object field update for 2 custom objects. I have a custom object called "Fund" which has a field called "service end date". Now i have another object called "Class" which is related to the Fund object. (You cannot have a class with out having a Fund"). What I would like to do is when a service end date is filled out at the fund level that it automatically updates the class end date.

Is this possible? Please let me know if I need to provide more information.

Thank you so much in advance!
Vishnu_SFDCVishnu_SFDC
Hi Jessica,

Try below trigger. it may contain some sysntax errors.

trigger updateclass on Fund(before update){
list<string> id = new list<string>();
map<string,date>  datemap = new map<string,date>();
for(fund f : trigger.new)
{
id.add(f.id)
datemap.put(f.id,service_end_date__c);
}

list<class__c> class = [select fund.id, service_end_date__c from class__c where fund.id in : id];

for(class__c c : class)
{
c.service_end_date__c = datemap.get(c.fund.id);
}
update class;
}
Thanks,
Vishnu