function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amateur1amateur1 

urgent issue

hi

 

this is my trigger when i am trying to insert two fulfilments of  same item and warehouse then its saying dupolicate id and is unable to update my list so how can i resolve my issue plz help

 

trigger Wow_Fulfillment_FIFO_SNUM_LOTNUM on Fulfillement__c (after insert,after update) {

public list<Inventory_Transaction__c> ITList1{get;set;}
ITList1 = new List<Inventory_Transaction__c>();


for(Fulfillement__c f:trigger.new)
{
Inventory_Transaction__c[] IT = [select id,Item__c,Qty_In__c,Dev_Bucket_Qty_Remaining__c,Qty_Out__c,warehouse__c
from Inventory_Transaction__c where Item__c =:FF.Item__c AND
Warehouse__c =:FF.warehouse__c AND Dev_Bucket_Qty_Remaining__c != 0
Order By Date__c asc];

 


IT[0].qty_out__c =IT[0].qty_out__c+FF.qty_out__c;
ITList1.add(IT[0]);

}
update ITList1;
}

i have updated it in the list to avoid dml staement error but its giving me duplicate id to update so plz help how to remove the duplicate id that comes into a list

Noam.dganiNoam.dgani
1. For your original issue, consider the following scenario - You have two fullfillments with the same value in item and warehouse and dev_qty... != 0 in the trigger list. Since in your inventory item query you order by date, you will get the same inventory item back from the query for both fullfilments ( in position 0 of the array ). For each of them you will put it in itlist1 and you can't have the same record in a list being DMLed. 2. Don't perform a query in a for statement, you will hit governer limits quickly (the limit is 100 queries per transaction). 3. You might want to validate that fields are not null before adding them (qty__c), this will cause a null pointer exception.
kritinkritin

trigger Wow_Fulfillment_FIFO_SNUM_LOTNUM on Fulfillement__c (after insert,after update) {
public list<Inventory_Transaction__c> ITList1{get;set;}
ITList1 = new List<Inventory_Transaction__c>();
set<string> sSetItems=new set<string>();
set<string> ssetWareHouse=new set<string>();

for(Fulfillement__c FF:trigger.new)
{
sSetItems.add(FF.Item__c);
ssetWareHouse.add(FF.warehouse__c);

}

Inventory_Transaction__c[] IT = [select id,Item__c,Qty_In__c,Dev_Bucket_Qty_Remaining__c,Qty_Out__c,warehouse__c
from Inventory_Transaction__c where Item__c in:sSetItems AND
Warehouse__c in:ssetWareHouse AND Dev_Bucket_Qty_Remaining__c != 0
Order By Date__c asc];

 

 

change as like above..then create Map to use it and update the values accordingly....