You need to sign in to do that
Don't have an account?

Trigger update child account field from parent
Hello,
On accounts we have a field called Category, that field is a Picklist. I would like to create a tirgger to update child accounts Category field with the value from parent account Category field.
This is what I have so far:
On accounts we have a field called Category, that field is a Picklist. I would like to create a tirgger to update child accounts Category field with the value from parent account Category field.
This is what I have so far:
trigger updateCategoryFromParent on Account (after insert, after update) { List<Account> accList = new List<Account>(); for (Account ac : Trigger.new) { if(ac.ParentId != null){ Account ap = new Account(); account au = new Account(Id = ac.Id); ap.Id = ac.ParentId; au.Category__c = ap.Category__c; accList.add(au); } } update accList; }
Try to use before event. To Avoid mulitple DML
Let us know if this will help you
All Answers
Try to use before event. To Avoid mulitple DML
Let us know if this will help you
I can't deploy thi without test coverdage. Would you be able to provide an example of a test for this trigger?