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
mark.peplowmark.peplow 

Internal Error - Roll-up summary

the follow trigger causes an internal error. i have a case outstanding with support but await their feedback. I am trying to count how many bookings have been made for one event. i have batch apex equivalent working no problem but i need realtime update of event totals. i have to use apex as event is a lookup from booking. any ideaas if the apex is wrong anywhere?

 

trigger UpdateEventRegistrantTotal on Booking__c (after insert, after update, after delete) {
Set <id> EventIDs = new Set<id>();

if(Trigger.isInsert || Trigger.isUpdate){
   for(Booking__c Book : trigger.new){
       if(!EventIDs.contains(Book.event__c)){
           EventIDs.add(Book.Event__c);
       }
   }
}
if(Trigger.isDelete){
   for(Booking__c Book: trigger.old){
       if(!EventIDs.contains(Book.Event__c)){
           EventIDs.add(Book.Event__c);
       }
   }
}
 map<Id,Double> EventMap = new map <Id,Double>();

  //Produce a sum of Booking__c and add them to the map
  //use group by to have a single event Id with a single sum value
  for(AggregateResult q : [select Event__c, Count(id)
    from Booking__c where Event__c IN :EventIDs group by Event__c]){
      EventMap.put((Id)q.get('Event__c'),(Double)q.get('expr0'));
  }

  List<Uni_Event__c> EventsToUpdate = new List<Uni_Event__C>();

  //Run the for loop on event using the non-duplicate set of event Ids
  //Get the sum value from the map and create a list of events to update
  for(Uni_Event__C E : [Select Id, No_of_Registrants__c from Uni_Event__c where Id IN :EventIds]){
    Double NoRegistrants = EventMap.get(E.Id);
    E.No_of_Registrants__c = NoRegistrants;
    EventsToUpdate.add(E);
  }

  update EventsToUpdate;


}

 

cheers

bob_buzzardbob_buzzard

Do you know at what point the internal server error occurs?  E.g. have you tried adding some debug to log the progression through the trigger?

mark.peplowmark.peplow

i escalated the issue to tier 3 support. they resolved the internal server error today. Apparently, the problem was caused because i had a chatter feed on the very same object i was using in my summary totals. By removing the chatter feed from the Booking object all works ok. Not that thats a solution to my problem since i do want a chatter feed. seems there's a problem with chatter feeds and child record access of some kind.

bob_buzzardbob_buzzard

Thanks for posting the outcome - one to add to the list of gotchas.