You need to sign in to do that
Don't have an account?
How to come accross "Too many script statements: 10201"
Hi all'
I got a exception as below. Any suggestions? Thanks in advance:
"Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger RentMergeTrigger caused an unexpected exception, contact your administrator: RentMergeTrigger: execution of BeforeUpdate caused by: System.Exception: Too many script statements: 10201: Class.RentMerge.RentCalculate: line 70, column 8"
Code:
public void RentCalculate(Account a){
Integer i = 1;
Decimal DCR = 0;
Decimal GrossMonthlyRent = 0;
Decimal H42=0;
Decimal K38=0;
Decimal GrossMonthlyExpense=0;
Decimal TotalExpenses=0;
Decimal BridgeCapitalRoundup=0;
Decimal BridgeC=0;
Decimal PMT1st=0;
Decimal PMT2nd=0;
Decimal JV_GIC_Consultant_Fee=0;
do
{
GrossMonthlyRent=i;
if (a.CMA_Property_Value__c > 250000){JV_GIC_Consultant_Fee=8500;}
else{JV_GIC_Consultant_Fee=7500;}
if (a.Condo_Fees__c == 0){
GrossMonthlyExpense=GrossMonthlyRent*0.15;
}else{
GrossMonthlyExpense=a.Condo_Fees__c;
}
H42=(GrossMonthlyRent*(1-0.05))-GrossMonthlyExpense-a.Rent_Tax__c;
//////////////////Caculate the updated TotalExpenses --> updated PMT1 and PMT2
BridgeC=a.X2nd_Mtg_Amount__c +a.X3rd_Mortgage_Amount__c + a.X4th_Mtg_Amount__c +a.X1st_Writ_Amount__c +
a.X2nd_Writ_Amount__c + a.X3rd_Writ_Amount__c
+ a.X1st_Caveat_Amount__c + a.X2nd_Caveat_Amount__c + a.X3rd_Caveat_Amount__c +
a.Misc_Expense_1__c + a.Misc_Expense_2__c + a.Misc_Expense_3__c + a.Misc_Expense_4__c
+ a.Misc_Expense_5__c + a.Misc_Expense_6_Amount__c +
a.Arrears_Estimate__c + a.Foreclosure_Legals_Estimate__c + a.LTV_Insurance__c +
a.Taxes__c + a.Processing_Fee_Bridge_Capital_GIC__c +
a.Appraisal__c + a.Title_Insurance__c + a.Real_Property_Report__c +
a.Renovations_Interior__c + a.Renovations_Exterior__c + a.Renovations_Extras__c
+ a.Payout_Penalty_Mortgage_1__c + a.Payout_Penalty_Mortgage_2__c +
a.Payout_Penalty_Mortgage_3__c + a.Payout_Penalty_Mortgage_4__c +
(GrossMonthlyRent-a.Rent_Payoff_Monthly__c)*6 + a.Legal_Fees_Purchase__c +
a.Legal_Fees_Purchase_Dispursments__c + a.Legal_Fees_Placing_New_Financing__c +
a.Legal_Fees_Placing_New_Fin_Dispursment__c + a.Legal_Fees_Sell__c +
a.Legal_Fees_Sell_Dispursment__c + a.Investor_Fee_1st_Mortgage__c +
a.Carrying_Costs__c + JV_GIC_Consultant_Fee +
JV_GIC_Consultant_Fee + a.Reserve_Contingency__c +
GrossMonthlyRent*6 + a.Selling_Realtor_Fees__c + a.Listing_Realtor_Fees__c;
BridgeCapitalRoundup=(Decimal)(math.round(BridgeC*1.05/1000))*1000;
TotalExpenses = a.X1st_Mtg_Amount__c + BridgeC + (BridgeCapitalRoundup/1.05)*(0.03+0.02) ;
If(TotalExpenses <= a.CMA_Property_Value__c*0.75)
{
PMT1st = TotalExpenses * ((0.058 / 12) / (1-math.pow((1+(0.058 / 12)),(-25*12))));
PMT2nd = 0;
}
else
{
PMT1st = a.CMA_Property_Value__c*0.75 * ((0.058 / 12) / (1-math.pow((1+(0.058 / 12)) , (-25*12))));
PMT2nd = (TotalExpenses - a.CMA_Property_Value__c*0.75)* ((0.15 / 12) / (1-math.pow((1+(0.15 / 12)) , (-25*12))));
}
////////////////////
K38=PMT1st+PMT2nd;
DCR=H42/K38;//line70
if (DCR <= 1.2 && i<20000){
i++;
}else{
i=0;
}
}while (i>0);
a.Rent__c=GrossMonthlyRent;
//}//end "for"
}//end of method
Hi,
I went through your code it appears that loop is executing too many times which is causing script exception i.e. to many statements are executing. It is happening beacuse i=0 is not executing beacuse (DCR<1.2) is always true and till the time (i<20000) becomes false before that script statement exception is thrown.
In order to overcome this you have to optimize you code. Can you please tell whats is bussiness logic behind the code, Whats sugnificance of DCR??