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
ShaliniShalini 

how to overcome the error: Too many script statements: 200001

Hi, 

 

Can anyone suggest a solution to overcome the error of "Too many script statements: 200001" in apex class.

 

I wanted to display the sum of resource amount in opportunity products for an Opportunity sorted by Account wise.

 

below is the sample code:

 

query resource amount from opportunity products sort by account name

 

put the opportunity inside SET to avoid duplicates (uniqoppid)

 

put the account id inside SET to avoid duplicates ( uniqaccid)

 

for(each unique account)

{

for(each unique opportunity)

{

for( sum resource amount from all opportunity products)

{

if(uniqoppid == opportunity in opportunity products && uniqaccid == opportunity product->opportunity->account id)

{

//code to display the resource amount

}

}

}

}

 

the above code in red line is the problem. It shows too many script statements: 200001

 

 

Message Edited by Shalini on 06-09-2009 06:03 AM
TehNrdTehNrd
If possible could you please post the actual code?
NguyenNguyen
You check condition exit in your loop, this error may be your loop can not exit.
whateverwhatever

Hi all,

 

I am runing into the same problem: Too many script statements: 10201, which happened at the highlighted line below. Any suggestions to come accross? This is my code:

 

 

public with sharing class RentMerge {
 
 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;
       
       if (DCR <= 1.2 && i<20000){
         i++;       
       }else{
        i=0;
       }
       
  }while (i>0);
     
     //save the final Gross_Monthly_Rent back to the Salesforce
     a.Rent__c=GrossMonthlyRent;
      
       //}//end "for"
   }//end of method

JuncalgaryJuncalgary

The problem was solved anyway. Thank you.

TehNrdTehNrd
Solution?