You need to sign in to do that
Don't have an account?
Rolando Esteves
Inserting a List<custom object> trigger only fires once
Hi,
When I insert a list of a custom object in apex it only fires my before insert for the first object on the list.
Anyone knows why ??
Thanks
Can you please provide code? The issue will be easier to solve with the code that is causing the issue.
Thanks!
Here is the code: When I insert the AllUnit list it fires the trigger for the first item on the list only
With this code at the end, the trigger will probably fire for every insert, but you will also hit your govornor limits as well.
If you comment out the "insert pto;" and uncomment the other two lines, you won't hit the governor limts.
The code that you would have to update is the trigger code. If you take a look at the first best practice in the Apex Code Best Practice wiki page, you will see that the need will be to do a for loop on each record in the trigger group.
I hope that helps!
I know this is bad practice but can you help me bulkify this trigger:
That should work. If it does, please mark this entry as solved.
Thanks!
You have a SOQL query inside a forr loop i think it might have some problems with governor limits.
That's a good point. In that case...I just thought of this: you're inserting these records, and the trigger is "before insert."
If you're already looking for the ID from the PriceBookEntry where the ProductCode matches l_PTO.Part_number__c...
If that's a lookup to the Product2 object, then you can get to the PriceBook that way....
Have you considered a workflow field update? I'm not 100% that would work, but a formula to populate the field with the Part_Number__c (if its a lookup to Product) to the Pricebook to the PriceBookEntry...
Not 100% sure that will work, but the options are really vast. If the Part_Number__c is a lookup to Product2, the best bet is to find the value through that chain of object relationships.
There no possible way to achieve this trough out workflows or formulas. Thanks for the help so far!
I need to bulk my trigger without affecting governor limits.
it should go something like this:
Is Part_Number__c a lookup to Product2? If so, you can do it through the relationship between Product and Pricebook. I'm not sure what you're trying to do is possible because it's going to create the list of all the Product Codes for every item in the Trigger.
Maybe what you need is a lookup to Product on product_opportunity__c. Or to Opportunity. Both have a lookup to the Pricebook object.
Product2 does not have a relation to the pricebookentry2. And from Opportunity you would need the OpportunityLineItem already created.
The Product will have a relation to a Pricebook, even if it's the Standard Pricebook. The Pricebook contains the Product price, and that pair is the PriceBookEntry. If there is a Product, and there is a PriceBookEntry, there needs to be a Pricebook. If you're trying to get the Pricebook entry for a Product, you're going to need the Pricebook. It's a transitive relationship: if you have two, you can get the third.
¿Can we call a another class passing the File as a parameter in order to process 75 more lines ?