You need to sign in to do that
Don't have an account?
Jon Foy
Code Error Help - writing a Trigger for a rollup summary on a cross object formula field.
Here's my code. Getting the following error: "Compile Error: Variable does not exist: ts.case_id @ line 9 column 79. That is the correct field. Any help would be greatly appriciated.
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, total_billable_amount__c from case where id =: ts.case_id];
c.total_billable_amount__c = rollUpAmount;
update c;
}
}
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, total_billable_amount__c from case where id =: ts.case_id];
c.total_billable_amount__c = rollUpAmount;
update c;
}
}
You are trying to access the variable ts.case_id from outside for loop, which obviously results in variable does not exist error.
Keep the below code in for loop it will work.
if(rollUpAmount != Null){
Case c = [select id, total_billable_amount__c from case where id =: ts.case_id];
And we should not use DML statements within for loop it fires a governer limit.Instead use Lists or Maps and execute DML operation on them out side for loop.
Regards,
Naveen
SSE , Salesforce CI expert group
http://www.autorabit.com"
rollUpAmount += ts.Billable_Amount__c;
ts.Billable_Amount__c will return a currency which contains decimals also.Change the data type of rollUpAmount.