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
Jagadeesh AdaveniJagadeesh Adaveni 

Unable to perform update operation?

Hi All,

I have written one triiger , it is performing deletion but unable to perform update. I did not get any error also
trigger reScheduleLogBooks on Log_Book__c (after update) {
    
    Set<String> subjects = new Set<String>();
    Set<String> students = new Set<String>();
  
    Set<id> set1 = new Set<id>();
    List<Log_Book__c> lbDelList = new List<Log_Book__c>();
    List<Log_Book__c> lbdl = new List<Log_Book__c>();
    Set<String> weeks = new Set<String>(); 
    List<Weeks__c> weekList = Weeks__c.getAll().values();
    Map<Integer,weeks__c> weekMap = new Map<Integer,weeks__c>();
    List<Log_Book__c> listToUpdate = new List<Log_Book__c>();
    List<Log_Book__c> lstToAdd = new List<Log_Book__c>();
    Set<Log_Book__c> setLog = new Set<Log_Book__c>();
    
    for(weeks__c week : weekList)
    {
        weekMap.put((Integer)week.Order__c,week);
         
    }
    
    for(Log_Book__c lbook : Trigger.old)
    {
        set1.add(lbook.Id);
        subjects.add(lbook.Subject__c);
        students.add(lbook.Student__c);
    }
    lbdl=[select Abacus__c, Absent_Time_Stamp__c, Absent__c, Attended__c, Class_Scheduled_Date__c, Collected_Book__c, Comments__c, Do_Not_Promote__c, English__c, Level__c, Order__c, Reason__c, Id, Student__c, Subject__c, Subjects_Registered__c, Week__c, Week_Day__c, gk__c, math__c from log_book__c where id in: set1 AND Subject__c in: subjects AND Student__c in: students ];
    
    
    for(Log_Book__c lbdelete : lbdl)
    {
        if(lbdelete.Class_Scheduled_Date__c>System.Today())
        {
           lbDelList.add(lbdelete);
           system.debug('@@@@@@@@@@Deleted Record is@@@@@@'+lbDelList);
        }
           
    }
    if(lbDelList.size()>0 && lbDelList!=null)
    {
    
        delete lbDelList;
    }
    
    
    if(stoprecursive.trigger1==true)
    {
        stoprecursive.trigger1=false;
    for(Log_Book__c lbUpdate : Trigger.new)
    {
            weeks.add(lbUpdate.week__c);
            subjects.add(lbUpdate.Subject__c);
            students.add(lbUpdate.Student__c); 
    }
    
    for(Log_Book__c lbup : [select Abacus__c, Absent_Time_Stamp__c, Absent__c, Attended__c, Class_Scheduled_Date__c, Collected_Book__c, Comments__c, Do_Not_Promote__c, English__c, Level__c, Order__c, Reason__c, Id, Student__c, Subject__c, Subjects_Registered__c, Week__c, Week_Day__c, gk__c, math__c from log_book__c where subject__c IN: subjects AND Student__c IN: students AND week__c IN: weeks AND Class_Scheduled_Date__c >=: system.today() order by order__c])
      {
          Integer weekLevel = 0;     
          String[] weekLevels = lbup.Week__c.split('-');
          //will get only week number of week__c field of Log_Book__c object selected value will store in first index 
          weekLevel = Integer.valueof(weekLevels[0]);
   
      if(lbup.Class_Scheduled_Date__c >= System.Today())
       {
           for(Integer j=weekLevel;j<27;j++)
           {
           
            lbup.Class_Scheduled_Date__c = lbup.Class_Scheduled_Date__c.addDays(7);
           
            //assigning custom setting value to week__c field based on selected week number from log_book__c object
            lbup.week__c = weekMap.get(weekLevel).name;
            system.debug('*************'+lbup.Class_Scheduled_Date__c + lbup.Level__c + lbup.Week__c);
            //lstToAdd.add(lbup);
            lstToAdd.add(lbup);
            weekLevel++;
            }
            //lstToAdd.add(lbup);
            weekLevel = 1;
        }
      }
     setLog.addAll(lstToAdd);
     listToUpdate.addAll(setLog);
    }
   
    //stoprecursive.trigger1=true;
    //delete lbDelList;
    update listToUpdate;

Thanks,
Jagadeesh
sandeep@Salesforcesandeep@Salesforce
Can you please check trigger1 boolean flag of class stoprecursive default value as if it is false this update code will be executed if it is defsult true then make sure logic for update must executed only once.

Please mark it is Best answer only if it actually helps you.
Thanks
Sandeep singhal
http://www.codespokes.com/