0

Question 1 : I am stuck while updating the custom object field(salary_c)

trigger TotalTheValue on Appointment__c (after insert, after update) {
   public decimal  Sum;
    list <decimal> tt =new  list <decimal>();
      List<Appointment__c> ap = new   List<Appointment__c>();
    List<Appointment__c> app = new   List<Appointment__c>();
     app =  [Select Salary__c ,total__c from Appointment__c where RecordTypeId='0122v000001c9OP'];
    
    if (app.size() > 0) {
     
  
    for ( Appointment__c c:app){
          
        c.Salary__c=300;
        
          system.debug('the value is app  ' + c );
        ap.add(c);
    } }

update ap;
}

but its show an error Update failed. First exception on row 0 with id a0x2v00000t6uJBAAY; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TotalTheValue: maximum trigger depth exceeded Appointment trigger event AfterUpdate Appointment how to fix this??

Question 2: I have two fields (total_cost__c and daily_cost__c) on custom object.I want to sum daily_cost__c of all records of that object and show the total value in total_cost__c ?

1 Answer 1

0

You're updating the same record again which causes the trigger to fire again and again. To need to have a recursive check to prevent updating the same record again.

You can check out this link: https://newstechnologystuff.com/2020/05/28/avoid-recursive-trigger-in-salesforce/

6
  • i don't want to use class with trigger?
    – user91246
    Jun 29, 2021 at 12:49
  • Though its a bad practice to write logic within the trigger itself. You can take a look at this: salesforce.stackexchange.com/questions/61371/… Jun 29, 2021 at 13:01
  • okay, got it. the remaining logic is good?
    – user91246
    Jun 29, 2021 at 13:06
  • solved question 1 thanks
    – user91246
    Jun 29, 2021 at 13:20
  • what about qustion 2???
    – user91246
    Jun 29, 2021 at 13:20

You must log in to answer this question.