You need to sign in to do that
Don't have an account?
error in trigger
How will i set and map methods this trigger?
trigger Inventorybid on bid__c (after update) {
List<id> accIds=new List<id>();
double sumTotal = 0;
List<servoTerra_Order__c> OrderUpdate = new List<servoTerra_Order__c>();
for (bid__c bidoffer : Trigger.new){
for (servoTerra_Order__c ord : [select Id, Name, total__c from servoTerra_Order__c where Id=:bidoffer.Order__c])
{
//Sum all the Total offer
for (bid__c bidtotal: [select Id,name,Total_Offer__c from bid__c where Order__c =:ord.id])
{
sumTotal += bidtotal.Total_Offer__c;
}
ord.total__c = sumTotal;
OrderUpdate.add(ord);
}
}
upsert OrderUpdate;
}
Update failed. First exception on row 0 with id a0TV00000003akPMAQ; first error:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Inventorybid: execution of
AfterUpdate caused by: System.ListException: Duplicate id in list:
a0UV0000000qI8nMAE Trigger.Inventorybid: line 33, column 1: []
Regardless of your error, you're going to want to rethink the way you are writing that trigger. You have a query within a loop and another query within that loop. If only 7 records got updated it would already break the query limit.
Hi
Definitely you need to use best practices for this trigger.
Solution to this problem is :
1. Update this List<id> accIds=new List<id>(); to
Set<id> accIds=new Set<id>();
2. change this OrderUpdate.add(ord); to
if(accIds.add(ord.id)){
OrderUpdate.add(ord);
}
let me know if you still face issue in it.