You need to sign in to do that
Don't have an account?
bharath kumar 52
Update a parent object's comment field when a child object's comment field is updated
Hi All,
Can someone give me the logic to write a trigger to update a parent object's comment field when a child object's comment field is updated.
for (Child_Obj CJ: trigger.new){
ParentObject POPrep = new ParentObject();
POPrep.Id = CJ.ParentId;
POPrep .Comment=CJ.Comment;
POUpdList.add(POPrep);
}
update POUpdList;
Hi Deepak,
That wouldn't work. Because you are trying to create an account from a contact......
I have mentioned "on update of child update the parent". But, the solution given is the other way round.
Thanks for your time.
I have guided you to loop thru the Child and update the Parent. It can be applied generically to any Child-Parent combination you want.
trigger Crunch on Contact (Before update) {
map<id,account>l1=new map<id,account>(l);
list<account>acc=new list<Account>();
Account up;
Map<id,account>m=new Map<id,account>();
for(contact c:trigger.new)
{
m.put(c.accountid,null);
}
list<account> l=[select id, comment__c from account where id in:m.keyset()];
for(contact d:trigger.new)
{
up=(l1.get(d.accountid));
up.comment__c=d.comment__c;
}
update up;
}