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
DoubleADoubleA 

Deployment log - Run failing

Hi, I'm receiving the following deployment log showing run failure.  Can anyone help in figuring out why it is failing.  

 

# Test Results:

Run Failures:
  Test_Contacts.myUnitTest System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateAccount: execution of AfterInsert

caused by: System.ListException: Duplicate id in list: 0018000000OI2VcAAL

Trigger.UpdateAccount: line 44, column 9

DoubleADoubleA

After reviewing the test class code I'm thinking the problem roots from my setting the whatid on the tasks repeatedly in the for loop (hence the error: Duplicate id in list: 0018000000OI2VcAAL) however, I'm unsure of a way around this.   

 

As an end result is there a way to insert tasks that are automatically associated to accounts for testing? 

 

@isTest private class Test_Contacts { static testMethod void myUnitTest() { // TO DO: implement unit test List<Task> tasks = new List<Task>{}; for(Integer i = 0; i < 100; i++){ Task t = new Task(Subject = 'Visit', whatid='0018000000OI2Vc'); tasks.add(t); } //start the test test.startTest(); //Insert the task records that cause the trigger to execute insert tasks; //stop the test test.stopTest(); //Query the database for the newly inserted records List<Task> insertedTasks = [SELECT Subject FROM Task WHERE Id IN: tasks];