You need to sign in to do that
Don't have an account?
Priya Mishra
In Account object we have a field called opportunity status and in opportunity object we have a field called
Stage so when stage value will change the new value should display in the
Account object field called opportunity status using trigger.
Trigger to Copy the child field value to the parent object custom field.
In Account object we have a field called opportunity status and in opportunity object we have a field called
Stage so when stage value will change the new value should display in the
Account object field called opportunity status using trigger.
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Please find below code I have used Account and Contact you can change object according to yours and fields also.
trigger updateParentField on Contact (after update) {
Map<ID,Account> contactMap = new Map<ID,Account>();
Set<Id> accountIdSet = new Set<Id>();
for(Contact con: trigger.new){
accountIdSet.add(con.AccountId);
}
contactMap = new Map<ID,Account>([SELECT id,Description,(SELECT id,Description FROM Contacts) FROM Account WHERE ID IN:accountIdSet]);
for(Contact con : trigger.new){
Account myNewAccount = contactMap.get(con.AccountId);
myNewAccount.Description = con.Description;
}
update contactMap.values();
}
Please mark it as a best answer if you found it helpful.
Thanks & Regards,
Abhishek Singh.
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas