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
swapna9swapna9 

Too many script statements: 200001

Hi,

 

Actually my requirement is under Price_Book__c related list is Revenue_Schedule__c ,under Revenue_Schedule__c related list  is  training_Schedule__c.

In Price_Book__c one button is there.once i click on that button it will open visualforce page and displays some fields from price_book__c,some fields from Revenue_Schedule__c and some fields from Training_schedule__c.In controller i am rolling up all the training schedule amount to the related revenue schedule and displaying in visual force page.First i got error as Too Many Soql Queries:101. So I kept query out side of the loop.after that amount is not rolling up properly.and again it is dispalying error as Too many script statements:200001.

 

Please any one give me suggestion.

 

My code is as follows:

 

public class MultipelRevenueEditFee
{

    public MultipelRevenueEditFee(ApexPages.StandardController controller) {

    }
   
    List<Double> Amount=new List<Double>();
    List<Double> FTES=new List<Double>();
    Double fte=0;
    Double amt=0;
    List<Price_Book__c> price = new List<Price_Book__c>();  
    public List<Price_Book__c> getprice()
    {
     //Price_Book__c pp=[select id, opportunity_Name__r.id,FTE_Based_Services__c,Related_FTE_Service__c from Price_Book__c where id =:ApexPages.CurrentPage().getParameters().get('id')];  
     price =[Select Name,                                
                 Related_FTE_Service__c,          
                 FTE_Based_Services__c,
                 RecordTypeID from Price_Book__c                
                  where id =: ApexPages.CurrentPage().getParameters().get('id')];      
     return price;
    
    }

   List<Revenue_Schedule__c> rev = new List<Revenue_Schedule__c>();
   public List<Revenue_Schedule__c> getrev()
   {
  
     rev=[Select Price_Book_Name__r.Name,                                
                 Fee_Based_Amount__c,          
                 Name,
                 Date__c,
                 No_of_FTE__c,
                 Additional_Fees__c,Total_Value__c,Date_by_Plan__c,No_of_FTE_Per_Month_by_Plan__c,Gain_Share_Amount_by_Plan__c,
                 Fee_Based_Amount_by_Plan__c,Date_by_Forecast__c,No_of_FTE_Per_Month_by_Forecast__c,Gain_Share_Amount_by_Forecast__c,
                 Fee_Based_Amount_by_Forecast__c,Date_by_A_C_Mgr_Estimate__c,Fee_Based_Amount_by_A_C_Mgr__c,Gain_Share_Amount_by_A_C_Mgr_Estimate__c,
                 No_of_FTE_Per_Month_by_A_C_Mgr__c,Date_by_Actuals__c,Fee_Based_Amount_by_Actuals__c,Gain_Share_Amount_by_Actuals__c,
                 No_of_FTE_Per_Month_by_Actuals__c,Total_Value_by_A_C_Mgr_Estimates__c,Total_Value_by_Plan__c,Total_Value_by_Actuals__c,
                 Price_FTE_in_US__c,Total_Value_by_Forecast__c,Comments__c,No_of_FTE_s_for_Training__c
                 from Revenue_Schedule__c
                 where Price_Book_Name__c =: ApexPages.CurrentPage().getParameters().get('id') order by date__c ];
                 return rev;    
   } 
   
   public List<Double> getAmount()
    {  
    List<Training_Schedule__c> Training= new List<Training_Schedule__c>();
    List<Revenue_Schedule__c> revenue=new List<Revenue_Schedule__c>();
    revenue=[select id,Date__c from Revenue_Schedule__c where Price_Book_Name__c=:price[0].Id];
    set<Id> pbID = new set<Id>();
    List<Revenue_Schedule__c> rsc = [select Id from Revenue_Schedule__c];
    for(Revenue_Schedule__c  p: rsc)  
    {
     pbID.add(p.Id);
    }
    Training = [select id,Amount__c,Revenue_Date__c,Incremental_FTEs__c,No_of_FTE_for_Training__c from Training_Schedule__c where  Revenue_Schedule__c IN: pbID];
    
    for(Integer k=0;k<revenue.size();k++)   
    {
        //Training=[select id,Amount__c,Revenue_Date__c from Training_Schedule__c where  Revenue_Schedule__c=:revenue[k].Id ];
        amt=0;   
        for(Integer j=0;j<Training.size();j++)
        {        
         if(Training[j].Amount__c!=null)
          {     
          amt=amt+(Training[j].Amount__c);                       
          }             
        }
         Amount.add(amt);          
    }
   
    return Amount;       
    }
    
       
       
    Public Id op;   
    Public PageReference return1()
    { 
        Price_Book__c p=[select id, opportunity_Name__r.id from Price_Book__c where id =:ApexPages.CurrentPage().getParameters().get('id')];
        op=p.opportunity_Name__r.id;
        PageReference Opp1 = new PageReference('https://cs1.salesforce.com/'+ op);
        Opp1.setRedirect(true);
        UPDATE rev; 
        UPDATE price;   
        return Opp1;  
    }
   
    Public Id I = ApexPages.CurrentPage().getParameters().get('id');   
    public PageReference save()    
    {  
        PageReference opp = new PageReference('https://cs1.salesforce.com/'+ I);
        Opp.setRedirect(true);       
        UPDATE rev; 
        UPDATE price;   
        return Opp;     
    }
   
 }

 

Thanks in advance..

 

Navatar_DbSupNavatar_DbSup

Hi,


You are hitting the governerlimit of script statement. Please go through the link below to resolve this:


http://www.tgerm.com/2010/02/apex-script-statements-reduction-tips.html


http://forceguru.blogspot.com/2011/04/saving-script-statements.html

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

swapna9swapna9

Thanks for ur reply,

 

I removed first for loop.So it is not giving too many script statements.But it is not rolling up properly.it is dispalying overall amount of training schedules related to all revenue schedules and displaying the amount in the first row of visual force page.I need to dispaly rollup of training schedule amount related to each revenue schedule record in visula force page record by record.i need to check both revenu schedule size and training schedule size.

 

i am new to set and maps.can u please tell me where i can do modification in the below code....

 

public List<Double> getAmount()
    {  
    List<Training_Schedule__c> Training= new List<Training_Schedule__c>();
    List<Revenue_Schedule__c> revenue=new List<Revenue_Schedule__c>();
    revenue=[select id,Date__c from Revenue_Schedule__c where Price_Book_Name__c=:price[0].Id];
    Map<id,Revenue_Schedule__c> Rmap =new Map<id,Revenue_Schedule__c>([select Id,Name from Revenue_Schedule__c limit 50000]);
    List<Revenue_Schedule__c> Rlist = Rmap.values();
    set<id> RIds = RMap.KeySet(); 
    Training = [select id,Amount__c,Revenue_Date__c,Incremental_FTEs__c,No_of_FTE_for_Training__c from Training_Schedule__c where  Revenue_Schedule__c IN: RIds  ];
    
    //for(Integer k=0;k<revenue.size();k++)   
    //{
        //Training=[select id,Amount__c,Revenue_Date__c from Training_Schedule__c where  Revenue_Schedule__c=:revenue[k].Id ];
        amt=0;   
        for(Integer j=0;j<Training.size();j++)
        {        
         if(Training[j].Amount__c!=null)
          {     
          amt=amt+(Training[j].Amount__c);                       
          }             
        }
         Amount.add(amt);          
    //}
   
    return Amount;       
   }

 

Thanks in advance