You need to sign in to do that
Don't have an account?
Ben Merton 15
Confusion on my first trigger
Merry Christmas!
I am trying to write my first trigger, and am really stuck with the method. I have three custom objects: Product__c, BOM__c, and BOM_Items__c
Product is the grandparent, BOM is the parent and BOM Items is the child.
I also have a lookup from BOM Items to Product, so effectively the Product is also the parent of BOM items. It is a strange, incestous relationship.
When I create a BOM Item, I want to trigger the ID of the Product in the BOM field, so that both BOM Items and BOM mention the Product. (ie trigger from the Product__c lookup field in the BOM__c object TO the Product__c lookup field in the BOM_Item__c field. This doesn't have to happen for ALL records ALL the time, only for the records as and when they are created.
As a novice, my initial thought on the methodology would be something like this:
However, when I read about triggers on these pages, everyone seems to start with having to build a map of the IDs and then selecting from the map to find the ID etc etc. I can't work out whether this is because they want to update more than one record at a time, or just because this is best practice. Please help!!
Ben
From what I can see on the boards, the methodology should be:
1. Build a map
I am trying to write my first trigger, and am really stuck with the method. I have three custom objects: Product__c, BOM__c, and BOM_Items__c
Product is the grandparent, BOM is the parent and BOM Items is the child.
I also have a lookup from BOM Items to Product, so effectively the Product is also the parent of BOM items. It is a strange, incestous relationship.
When I create a BOM Item, I want to trigger the ID of the Product in the BOM field, so that both BOM Items and BOM mention the Product. (ie trigger from the Product__c lookup field in the BOM__c object TO the Product__c lookup field in the BOM_Item__c field. This doesn't have to happen for ALL records ALL the time, only for the records as and when they are created.
As a novice, my initial thought on the methodology would be something like this:
trigger ProductName on BOM_Item__c (before insert, before update) { BOM.Product__c ProductIDBOM; Product__c ProductIDBOMItem; for (BOM_Item__c trigger : trigger.new) { ProductIDBOM=BOM__c.Product__c; ProductIDBOMItem=ProductIDBOM; } }
However, when I read about triggers on these pages, everyone seems to start with having to build a map of the IDs and then selecting from the map to find the ID etc etc. I can't work out whether this is because they want to update more than one record at a time, or just because this is best practice. Please help!!
Ben
From what I can see on the boards, the methodology should be:
1. Build a map
All Answers