Create one percentage field on Account with API Name Discount__c. Task : Create one apex trigger on account so that whenever the value of Discount__c field is update on parent account, the same value must be updated on the child accounts of the parent.
Here what i have done till now i'm sharing the code but i'm not able to contain the error
A non foreign key field cannot be referenced in a path expression: ParentId
Here is my code --
trigger testAccountTrigger on Account (after update) {
List<Id> acctId = new List<Id>();
List<Account> acctToUpdate = new List<Account>();
for(Account acc : Trigger.new) {
acctId.add(acc.ParentId);
}
for(Account a : [select id,Discount__c from Account where id in: acctId])
{
for(Account ac : trigger.new)
{
a.Discount__c = ac.ParentId.Discount__c;
acctToUpdate.add(a);
}
}
if(acctToUpdate.size()>0) {
update acctToUpdate;
}
}
how to solve this issue