You need to sign in to do that
Don't have an account?
troble while deploying a trigger
Hi All
I had wrote atrigger and facing difficult in deploying. The think is it is trowing an error in an different apex test class. please have a look at my trigger(Update account) and the error is showing in an different apex test class(Test_Opportunitytoorder) which i mentioned in Red
trigger UpdateAccount on Opportunity (after update)
{
List<id> accIds=new List<id>();
for (Opportunity opp : trigger.new)
{
accIds.add(opp.accountid);
}
Map<Id, Account> accountsById=new Map<Id, Account>();
List<Account> accs= [select id,Ready_to_Wincare__c from Account where id in :accIds];
accountsById.putAll(accs);
List<Account> accsToUpdate=new List<Account>();
for (Opportunity opp : trigger.new)
{
if (opp.StageName == 'Closed Won')
{
Account acc=accountsById.get(opp.AccountId);
acc.Ready_to_Wincare__c = True;
accsToUpdate.add(acc);
}
}
update accsToUpdate;
}
Errors
Test_OpportunityToOrder.testOpportunityToOrder System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateAccount: execution of AfterUpdate
caused by: System.ListException: Duplicate id in list: 0014000000XtFyyAAF
Trigger.UpdateAccount: line 22, column 1: []
I think that this should fix the issue..
All Answers
Make sure you don't have duplicate Accounts being updated in the same Update DML statement.
To troubleshoot, System.debug() the accountIds being updated before you update to see if you have duplicates.
I think that this should fix the issue..
Thankyou ver muck..the code has fixed my issue. Appreciate your help
Thanks
Sree