can anybody help me here. I am not able to push a trigger into production, I am getting this error for all the test.classes. I hope someone can tell me what is wrong here. I will appreciate any help.
Error:
Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateOSOTrigger: execution of AfterInsert caused by: System.ListException: Duplicate id in list: a0i40000003CpULAA0 Trigger.updateOSOTrigger: line 43, column 1: []", Failure Stack Trace: "Class.OS...
Trigger:
trigger updateOSOTrigger on SO_Detail__c (after insert, after update, before delete) {
Outbound_Sales_Order__c [] oso = new Outbound_Sales_Order__c[]{};
if(Trigger.isInsert || Trigger.isUpdate){
for(SO_Detail__c p : Trigger.new){
if(!String.isEmpty(p.Outbound_Sales_Order__c)){
oso.add(new Outbound_Sales_Order__c(
Id = p.Outbound_Sales_Order__c,
x1_Issue__c = String.valueof(p.SOD_Issue__c),
x2_Issue__c = String.valueof(p.x2_Issue__c),
x3_Issue__c = String.valueof(p.x3_Issue__c),
x4_Issue__c = String.valueof(p.x4_Issue__c),
x5_Issue__c = String.valueof(p.x5_Issue__c),
x6_Issue__c = String.valueof(p.x6_Issue__c)
));
}
}
}
if(Trigger.isDelete){
for(SO_Detail__c p : Trigger.old){
if(!String.isEmpty(p.Outbound_Sales_Order__c)){
oso.add(new Outbound_Sales_Order__c(
Id = p.Outbound_Sales_Order__c,
x1_Issue__c = '',
x2_Issue__c = '',
x3_Issue__c = '',
x4_Issue__c = '',
x5_Issue__c = '',
x6_Issue__c = ''
));
}
}
}
update oso;
}
Test Class
@isTest
public class test_updateOSOTrigger {
static testMethod void updateOSOTrigger_Test() {
Profile pf = [Select Id from Profile where Name = 'System Administrator'];
User u55 = new User();
u55.FirstName = 'Test';
u55.LastName = 'User';
u55.Email = 'testuser@test123456789.com';
u55.CompanyName = 'test.com';
u55.Title = 'Test User';
u55.Username = 'testuser@test123456789.com';
u55.Alias = 'testuser';
u55.CommunityNickname = 'Test User';
u55.TimeZoneSidKey = 'America/Mexico_City';
u55.LocaleSidKey = 'en_US';
u55.EmailEncodingKey = 'ISO-8859-1';
u55.ProfileId = pf.Id;
u55.LanguageLocaleKey = 'en_US';
insert u55;
system.runAs(u55){
Test.startTest();
Account account = new Account(Name = 'Test Account1');
insert account;
NRProducts__c product2 = new NRProducts__c(Account__c = account.Id, Name = '105823437');
insert product2;
Entity__c ent = new Entity__c(name='CarlosStore') ;
insert ent;
Outbound_Sales_Order__c ososo = new Outbound_Sales_Order__c(Entity__c= ent.id ,X1_Issue__c = '2', X2_Issue__c = '2', X3_Issue__c = '2', X4_Issue__c = '2', X5_Issue__c = '2',X6_Issue__c = '2');
insert ososo;
update ososo;
SO_Detail__c detail = new SO_Detail__c(Outbound_Sales_Order__c = ososo.id, NRProducts__c = product2 .id);
insert detail;
update detail;
delete detail;
System.assertequals( detail.Outbound_Sales_Order__c , ososo.id);
System.assertequals( '2', ososo.X1_Issue__c);
System.assertequals( '2' , ososo.X2_Issue__c);
System.assertequals('2' , ososo.X3_Issue__c);
System.assertequals( '2' , ososo.X4_Issue__c);
System.assertequals( '2' , ososo.X5_Issue__c);
System.assertequals( '2' , ososo.X6_Issue__c);
Test.stopTest();
}
}
}