You need to sign in to do that
Don't have an account?
bulk trigger not firing -- not sure why?
Here's a bulk trigger I just wrote (I am new to this)... and it looks ok on paper.
But when I add or update 1 record in the sandbox... the parent record remains unchanged. Nothing happens... not even an incorrect answer.
Any thoughts?
Basic idea of the trigger is to update parent record (Student__c) when child records (Student_Call_Log__c) is changed. I update the following fields on the Student__c object: call count, most recent call note and tech_support_log__c.
trigger Bulk_CallLogs on Student_Call_Log__c (after insert, after update) { // 1. Loop through Trigger.new & throw the relevent info in a list (either list of leads, list of lead id's, etc) // 2. Use the list to query related objects to populate another list // 3. Loop through the 2nd list to create a map of LeadID to related object // 4. Loop again through Trigger.new to add the related info to Lead using the map from #3 list<Student_Call_Log__c> list_thelogs = new list<Student_Call_Log__c>(); // list contains all of the logs being processed // Step 1 set <id> list_relatedstudents_temp = new set <id> (); for (Student_Call_Log__c log :list_thelogs) { list_relatedstudents_temp.add(log.related_student__c); } list<Student__c> list_relatedstudents = ([select id, Most_Recent_Call_Note__c, Tech_Support_Logs__c, Call_Count__c from Student__c where id IN :list_relatedstudents_temp]); // Step 2 list<Student_Call_Log__c> list_relatedlogs = ([select id, related_student__c, date__c, note__c from Student_Call_Log__c where related_student__c IN :list_relatedstudents order by Date__c DESC ]); list<Student_Call_Log__c> list_relatedlogs_mostrecent = ([select id, related_student__c, date__c, note__c from Student_Call_Log__c where related_student__c IN :list_relatedstudents order by Date__c DESC limit 1 ]); map<id, id> map_students = new map<id, id>(); map<id, date> map_log_date = new map<id, date>(); map<id, String> map_log_calltype = new map<id, string>(); map<id, String> map_log_callresult = new map<id, string>(); map<id, String> map_log_note = new map<id, string>(); map<id, Integer> map_log_counter = new map <id, integer>(); Integer counter = 1; //Step 3-A for (Student__c s :list_relatedstudents) { for (Student_Call_Log__c log :list_relatedlogs) { map_students.put(s.id, log.id); map_log_date.put(log.id, log.Date__c); map_log_calltype.put(log.id, log.Call_Type__c); map_log_callresult.put(log.id, log.Call_Results__c); map_log_note.put(log.id, log.note__c); map_log_counter.put(log.id, counter); } } //Step 4-A String temp_lognote = null; counter = 0; for (Student__c s :list_relatedstudents) { for (Student_Call_Log__c log :list_relatedlogs) { temp_lognote = temp_lognote + map_log_date.get(log.id) + ' -- ' + map_log_calltype.get(log.id) + ' -- ' + map_log_callresult.get(log.id) + ' -- ' + map_log_note.get(log.id) + '\n'; counter = counter + map_log_counter.get(log.id); } s.Tech_Support_Logs__c = temp_lognote; s.Call_Count__c = counter; temp_lognote = null; counter = 0; } //Step 3-B map<id, id> map_students_mostrecent = new map<id, id>(); map<id, string> map_log_mostrecentnote = new map<id, string>(); for (Student__c s :list_relatedstudents) { for (Student_Call_Log__c log :list_relatedlogs_mostrecent) { map_students_mostrecent.put(s.id, log.id); map_log_mostrecentnote.put(log.id, log.note__c); } } //Step 4-B for (Student__c s :list_relatedstudents) { for (Student_Call_Log__c log :list_relatedlogs_mostrecent) { s.Most_Recent_Call_Note__c = map_students_mostrecent.get(log.id); } } //Update records update list_relatedstudents; }
I didn't look at the code in detail, but it seems you are not referencing trigger.new
}
replace list_thelogs with trigger.new:
}
I would also recommend leveraging our system.debug statements to evaluate the logic.
All Answers
I didn't look at the code in detail, but it seems you are not referencing trigger.new
}
replace list_thelogs with trigger.new:
}
I would also recommend leveraging our system.debug statements to evaluate the logic.
THANKS!
That was it.