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
vibrationvibration 

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: []

adamproadampro

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. 

Shashikant SharmaShashikant Sharma

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.