If you want to update data in Parent object when child is created or updated, then you should have your trigger on Child. Or if you want to update data on Child when parent is updated, keep your trigger on parent.
Inn general life, first scenario is very normal when you update data in parent when child is created/updated
Trigger can be written on almost all objects. However it totally depends on how is your requirement and how your use cases are kicked of. So if there is a use cases that relates to parent object, you need to write a trigger on parent to do the processing you want to do. same is the case for child object. So if there are multiple use cases and relates to both parent and child object which can initiate the required processing, you would be required to write triggers on both objects. In Nutshell, you need to nail down your reuirement into use cases and then think which object you should write trigger on.
Generally speaking, if the child could alter the parent's value, then the trigger should generally be on the child.
Depending on the use case, you might have two triggers, one on the parent, and one on the child. The child would simply update the parent, then the parent would query for all children. This can be useful when you need to know, for example, the total number of records on the parent.
Hey bs881026 ,
It is completely depends on the requirement .
But we can write trigger on Child /parent object to fetch desired result .
Lets suppose A is parent to B . So B is child .
Soql will be like ,if trigger is on Parent object :
Select Id ,(select Id from B__r) from A
And if trigger is on Child object,then soql will be like this :
Select A__r.id , id from B .
Inn general life, first scenario is very normal when you update data in parent when child is created/updated
Hi bss881026,
Trigger can be written on almost all objects. However it totally depends on how is your requirement and how your use cases are kicked of. So if there is a use cases that relates to parent object, you need to write a trigger on parent to do the processing you want to do. same is the case for child object. So if there are multiple use cases and relates to both parent and child object which can initiate the required processing, you would be required to write triggers on both objects. In Nutshell, you need to nail down your reuirement into use cases and then think which object you should write trigger on.
Regards
Depending on the use case, you might have two triggers, one on the parent, and one on the child. The child would simply update the parent, then the parent would query for all children. This can be useful when you need to know, for example, the total number of records on the parent.