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

My trigger is not working for me need help badly...

I keep getting self reference errors and I do not know what to do anymore please help:


trigger updatesaandtermtrigger on Course_History__c (before insert, before update) { for (Course_History__c ch : Trigger.New){ updatech.updatecoursehistory(ch.Id, ch.Subject_Area__c,ch.GL_Term_Value__c); } } Public class updatech{ public static void updatecoursehistory(Id chid, String Subject, Decimal Term){ List<Subject_Area_RQ__c> sarq=new List<Subject_Area_RQ__c>([Select Id,GL_Term_Value__c FROM Subject_Area_RQ__c where GL_Term_Value__c=:Term and Subject_Area__r.Name=:Subject Limit 1] ); System.Debug('chid, Subject, Term - ' + chid + Subject + Term); System.Debug('GLTerm - ' + String.Valueof(sarq[0].GL_Term_Value__c)); System.Debug('Id - ' + sarq[0].Id); for(Course_History__c chi :[Select Term__c,Subject_Area_RQ__c from Course_History__c where id=:chid Limit 1]){ chi.Term__c = String.Valueof(sarq[0].GL_Term_Value__c); chi.Subject_Area_RQ__c= sarq[0].Id; update(chi); } } }





You are updating course_history__c in your updatech class which will recursively cause your trigger to execute again (and again). The Cookbook has a recipe titled "Controlling Recursive Triggers" which should solve your problem.