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
jd123jd123 

Too many script statements: 200001

Hi All 

 

 Even i am remving soql statements from for loop it is giveing error 

 

 

        

Visualforce Error
 


System.LimitException: FConnect:Too many script statements: 200001

Error is in expression '{!Add}' in component <apex:page> in page fconnect:selected_products_underservice

 

 

External entry point

 

public with sharing class SelectedProductsunderservice
{
public String AgreementLineId;
public String Customer;
public String customerName;
Public List<Products__c> Products;
Public List<Product__c> customProducts;
public List<ProductsUnderService> ProductsUnderServiceList{get;set;}
List<Id> proIds = new List<Id>();
List<Id> iprodIds = new List<Id>();

public SelectedProductsunderservice ()
{
customProducts = new List<Product__c>();
AgreementLineId=apexpages.currentpage().getparameters().get('Agreement_Line');
Agreement_Line__c al=[select id,Agreement__r.Customer__r.name from Agreement_Line__c where id=:AgreementLineId LIMIT 10 ];
Customer=al.Agreement__r.Customer__c;
customerName=al.Agreement__r.Customer__r.name;

Products = [SELECT id,name ,Agreement_Line__c,Products_ID__c FROM Products__c WHERE Agreement_Line__c=:al.id LIMIT 10];

for(Products__c pro : Products)
{
proIds.add(pro.Products_Id__c);
}

customProducts = [SELECT Id, Name FROM Product__c WHERE Id IN :proIds];
}

public List<ProductsUnderService> getProductsUnderService()
{
ProductsUnderServiceList=new List<ProductsUnderService> ();
List<Installed_Products__c> iproducts = [select Name,
Description__c,
Serial_ID__c,
Asset_Tag__c,
Quantity__c,
Agreement_Line__c,
Products__c,
Site__c,
Customer__c from Installed_Products__c where Customer__c=:customer AND Products__c IN:proIds limit 4];

For(Installed_Products__c ip :iproducts )
{
iprodIds.add(ip.Id);
}
List<Products_Under_Service__c> Productserrvice =[select id,name,Installed_Productss__c from Products_Under_Service__c
where Agreement_Line__c=:AgreementLineId AND Installed_Productss__c IN:iprodIds LIMIT 10 ];

For(Installed_Products__c ip :iproducts )
{
integer i=0;
For(integer temp=0;temp<Productserrvice .size();temp++ )
{
if(Productserrvice[temp].Installed_Productss__c == ip.id)
i++;
}
if(i==0)
ProductsUnderServiceList.add(new ProductsUnderService(ip));
}
if(ProductsUnderServiceList.isEmpty())
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,+ 'There are no Installed Products for '+customerName+' Account'));
return ProductsUnderServiceList;
}

public PageReference Add()
{
//List<Products_Under_Service__c> listPus;
List<Products_Under_Service__c> listPus = new list<Products_Under_Service__c> ();
Products_Under_Service__c pus;
for(ProductsUnderService ip:ProductsUnderServiceList)
{
if(ip.selected==true)
{
pus= new Products_Under_Service__c(Installed_Productss__c=ip.id,
Agreement_Line__c =AgreementLineId);
//insert Pus;
listPus.add(pus);
}

}
insert listPus;
PageReference p=new PageReference('/'+AgreementLineId);
return p;
}
public PageReference cancel()
{
PageReference p=new PageReference('/'+AgreementLineId);
return p;
}

public class ProductsUnderService
{
public Installed_Products__c con {get; set;}
public String id{get;set;}
public Boolean selected {get; set;}
//public String aggreementLine{get;set;}

public ProductsUnderService(Installed_Products__c ip)
{
id=ip.id;
con = ip;
selected = false;
}
}
}

 

 

 

<apex:page controller="SelectedProductsunderservice">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons id="id">
<apex:commandButton value=" Add " action="{!Add}" reRender="id"/>
<apex:commandButton value="Cancel" action="{!cancel}" reRender="id"/>
</apex:pageBlockButtons>
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockTable value="{!ProductsUnderService}" var="ip" id="table">
<apex:column headerValue="Action">
<apex:inputCheckbox value="{!ip.selected}"/>
</apex:column>

<apex:column value="{!ip.con.Name}"/>
<apex:column value="{!ip.con.Products__c}"/>
<apex:column value="{!ip.con.Description__c}"/>
<apex:column value="{!ip.con.Serial_ID__c}"/>
<apex:column value="{!ip.con.Asset_Tag__c}"/>
<apex:column value="{!ip.con.Quantity__c}"/>
<apex:column value="{!ip.con.Customer__c}"/>

</apex:pageBlockTable>
</apex:pageBlock>

</apex:form>
</apex:page>

 

Any help is Appriciated 

Anu Raj.ax1269Anu Raj.ax1269

Hi

 Try with out reRender="id"

  <apex:commandButton value=" Add " action="{!Add}" />

thanks 

Anu

jd123jd123

HI Anu Raj

 

same error

 

 

Visualforce Error
 


System.LimitException: FConnect:Too many script statements: 200001

Error is in expression '{!Add}' in component <apex:page> in page fconnect:selected_products_underservice

 

 

External entry point

jungleeejungleee

Hi ,

 

I think this error comes up when your for loop runs for more than 200000 times. You need to somehow, may be by adding where clause in the SOQL query  before passing the list in the for loop, refine your code to make sure that you reduce the number of times the code loops thru..

 

Regards

Sam

maja madi

Gunners_23Gunners_23

Please find the below link for reducing the script statements

 

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