Hi I got an after insert trigger,which i am testing.When i try to test for 200records, it is giving me an exception as below

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Before Insert or Upsert list must not have two identically equal elements: []

and this is the code in my testclass:

 //create a custom object1 record
    customobject1__c p1 = new customobject1__c(Name = 'Program1');
    insert p1;

    //Create a customobject2 record 
   customobject2__c p2 = new customobject2__c(Name='T1',customobject1__c = prog.id);
   insert p2;

//create an account    
   Account accrec = new account(name = 'Account');

//Create a list of 200 customobject3 records
   list<customobject3__c> proll = new list<customobject3__c>();     
     for(integer i = 0;i<200;i++)
     proll.add(new customobject3__c(customobject2__c = p2.id, Account__c = accrec.id ));

When loop is for 1record,it works fine.But when more,it gives this error.I cannot figure out whey. I know a loop that is going to be inserted if has duplicate sobjects that will give an error. Since i am adding different sobjects by specifying proll.add(new. It shouldnt be confusing that same sobjects are there? ERROR FOUND: Error was actually in trigger.When i try running this piece of code,with my trigger inactivated in anonymous it worked.in my trigger i was assigning same sobject in list.and that was the reason for this

  • 1
    can you post your trigger code ?Is error coming from only test code or your trigger itself – Mohith Shrivastava Aug 9 '13 at 15:17
  • It is from the testcode when i change code in testclass to below it works fine (changed loop to execute only once) //Create a list of 200 customobject3 records list<customobject3__c> proll = new list<customobject3__c>(); for(integer i = 0;i<1;i++) { proll.add(new customobject3__c(customobject2__c = p2.id, Account__c = accrec.id )); } – sfdc99999 Aug 9 '13 at 15:18
  • also customobject3 is a junction object,if that makes any difference – sfdc99999 Aug 9 '13 at 15:22

Your error message states that it is a custom validation rule; I would check the validation rules in place for customobject3__c, customobject2__c, and Account.


Check what the unique key / external id is for customobject3. You are probably trying to insert duplicate records. Perhaps there is another field in that object you need to set which is null and causing the duplicate error.

  • There is no external id/unique fields on customobject 3.If it was case of not passing a field ,that is causing this issue,it should not work for even a single record.But this comes up,only when loop is more than 1 – sfdc99999 Aug 9 '13 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.