+ Start a Discussion
Jon FoyJon Foy 

Need Help Writing A Trigger to run a Roll up Summary on a Cross Object Formula Field

I believe I've ran into a limitation in SF, in that I cannot create a roll up summary on a cross object formula field.  Here's my scenario:

We have a custom Object: TimeSlip__c, which contains a field "Billable_Amount__c" that is a cross object formula.  It take the "Rate__c" from another related object (Case_Resource__c) and multiplies it by the number of hours entered on the TimeSlip (Total_Billable_Time__c).  

I'm trying to create a rollup summary on the Case Page that calculates the toal Billable Amount from all timeslips by rolling up the "Billable_Amount__c" field, but SalesForce isn't giving me this option.

I've been told I can achieve this with a trigger, and need some help writing the Apex Code.
Pavan DavePavan Dave
Need to write trigger on Time Slip object.

Trigger timeSlipTrigger on TimeSlip__c (after insert, after udpate){
     Integer rollUpAmount;
     for(TimeSlip__c ts : Trigger.New){
          if(ts.Billable_Amount__C != Null){
               rollUpAmount += ts.Billable_Amount__c;     //Suppose you want to add all in Rollup logic
          }
     }
     if(rollUpAmount != Null){
          Case c = [select id, name, rollupfield from case where id =: ts.case__c.id];
          c.rollupfield = rollUpAmount;
          update c;
     }
     
}
Jon FoyJon Foy
Here's the code I'm using now:
trigger UpdateCaseBillableAmount on TimeSlip__c (after insert, after update) {
     Integer rollUpAmount;
     for(TimeSlip__c ts : Trigger.New){
          if(ts.Billable_Amount__C != Null){
               rollUpAmount += ts.Billable_Amount__c;     //Suppose you want to add all in Rollup logic
          }
     }
     if(rollUpAmount != Null){
          Case c = [select id, name, total_billable_amount__c from case where id =: ts.case__c.id];
          c.rollupfield = rollUpAmount;
          update c;
     }
}


i'm getting the following errors:
"no such column 'name' on entity 'Case'."
and if I remove 'name' i get this:
"variable does not exist: ts.case__c.id @ line 9 column 79