You need to sign in to do that
Don't have an account?
Trudge
Trigger That Updates a Lookup Field Not Firing When Referencing Same Record During Bulk Upload
I have a trigger that updates a lookup field based on the value of a text field. It's working great with the bulk uploads I'm doing, except when the bulk uploads reference the same record for lookup. The lookup field (Customer Product Mix) populates on the first record, but fails to do so on subsequent records only when the same lookup record is referenced.
Here is the code we're using, which I thought was bulkified since all other records populate just fine on a bulk upload. Any help would be greatly appreciated.
Here is the code we're using, which I thought was bulkified since all other records populate just fine on a bulk upload. Any help would be greatly appreciated.
trigger UpdateCustomerProductMix on Sales_Order_Line_Item__c (before insert, before update ){ Map<String, Sales_Order_Line_Item__c> CPMToSOLIMap = new Map<String, Sales_Order_Line_Item__c>(); for(Sales_Order_Line_Item__c soli:Trigger.new) { CPMToSOLIMap.put(soli.Customer_Product_Mix_UploadID_HIDDEN__c, soli); } List<Customer_Product_Mix__c> cpmLst = [SELECT ID, Name FROM Customer_Product_Mix__c where Name in :CPMToSOLIMap.keySet()]; for(Customer_Product_Mix__c cpm : cpmLst){ CPMToSOLIMap.get(cpm.Name). Customer_Product_Mix__c = cpm.ID; } }
Maps don't allow adding up duplicate keys. As a result, you are unable to perform updates on same reference look-up.
You need to reform your code as below.
Hope this helps ...!!!
All Answers
Maps don't allow adding up duplicate keys. As a result, you are unable to perform updates on same reference look-up.
You need to reform your code as below.
Hope this helps ...!!!
Cheers,
Chad