You need to sign in to do that
Don't have an account?
d.tejdeep@nicomatic.in
I am trying to insert two parents with two childs attached each .
This is my save method :
I am getting the error like this
System.ListException: Before Insert or Upsert list must not have two identically equal elements
It is throwing the error in this
upsert batchListToInsert;
Please provide me best solution for this :
Thanks in Advance
how to get rid of this error ?System.ListException: Before Insert or Upsert list must not have two identically equal elements
public Quotelineitem_IBC(ApexPages.StandardController controller){ flag=true; qouteLineItemMap=new map<Integer,Quote_line_Item__c>(); batchMap=new Map<integer,List<Batch__c>>(); //Capturing parent Quote id from URL parentId=Apexpages.currentPage().getParameters().get('ParentId'); //Adding new QuoteLineItem without batches to map which will be displayed after loading the page count=2; count1=2; List<Batch__c> listBatchToadd=new List<Batch__c>(); For(integer i=0;i<count;i++){ qouteLineItemMap.put(i+1,new Quote_line_Item__c(Quote1__c=parentId)); } For(integer j=0;j<count1;j++){ batch__c b=new batch__c(); listBatchToadd.add(b); batchMap.put(j+1,listBatchToadd); } quoteLineItemMapsize=qouteLineItemMap.size(); }//End of constructor
I am trying to insert two parents with two childs attached each .
This is my save method :
public pageReference save1(){ //Local varibles and instance List<Quote_Line_item__c> listtoinsert =new List<Quote_Line_item__c>(); List<Batch__c> batchListToInsert =new List<Batch__c>(); List<Integer> sortkey=new List<Integer>(); sortkey.addAll(qouteLineItemMap.keySet()); for(integer qli:sortkey){ listtoinsert.add(qouteLineItemMap.get(qli)); }//End of for // Inserting the list of QuoteLine Items try{ upsert listtoinsert; } catch(DmlException de){ return null; } //Iterating the loop to store the list of Batches which are going to be inserted into the databse for(integer qli:sortkey){ for(Batch__c bat: batchMap.get(qli)){ if(bat.Asked_Qty__c!=Null){ bat.Quote_Line_Item__c=qouteLineItemMap.get(qli).id; } batchListToInsert.add(bat); }//End of for }// End of for try{ upsert batchListToInsert; } catch(DmlException de){ return null; } }//End of method
I am getting the error like this
System.ListException: Before Insert or Upsert list must not have two identically equal elements
It is throwing the error in this
upsert batchListToInsert;
Please provide me best solution for this :
Thanks in Advance
batchSetToInsert= new Set<Batch__c>(batchListToInsert);
upsert batchSetToInsert;
Here's the full code:
Thanks for your reply
But still i am facing the issue
chagne this;
upsert batchSetToInsert;
To this:
batchSetToInsert.addAll(batchListToInsert);
batchListToInsert.addAll(batchSetToInsert);
upsert batchListToInsert;
If this does not work then I will need to test myself.
thx