+ Start a Discussion
kito kidkito kid 

System.LimitException: Too many code statements: 200001

Below is my code.


companyList = [
            Select a.Id,a.Name, a.Phone, a.Website, etc... From Account a
            Where a.RecordType.Name = 'Blah'
String csvString = '';
        for(Account company : companyList)
            csvString += myUtil.formatCSVString(company.Id) + ','
                        + myUtil.formatCSVString(company.Name) + ','
                        + myUtil.formatCSVString(company.Phone) + ','


How can I solve this error?

I am not doing any insert or update. I am just only select the data and want to do necessary thing.



Poosibly you can try these one's-


1-Use SOQL for loop like below...

for(Account a:[select id,name from account]){


2-Put the code in future call.

3-Limit the iteration by putting more filters

kito kidkito kid

Hi UV, just an extended question.
1) Why does it happen?

2) Is it because of too many debugging logs line ?

3) or is it because of accessing to DB so many time? But I believe, I only access to DB only once using Select statement and put into object. And using this object, I access its value.

Can you please clarify my understanding?

And I believe this happen because I call myUtil class function for to format each data of each record from DB.

As this is the necessary step to format each data , how can I achieve it without hitting the error?

Any suggesstion?




Its the number of lines of code being executed in single context. In your case execution of code within for loop depends on the records returned by the query.So for each record set of lines would be executed and that would be counted agaist this limit.Please try the suggestions.

kito kidkito kid

Hi UV, I use 1.Use SOQL for loop as you mentioned. Still error.
2. I can't put the code in future call. As I want string return back form that method.
3.for limitation the of filters, I already use in SOQL statement by using WHERE.

The way I want to do is below.
1) I will query with Where condition from DB.
2) for each record, I need to parse its data by calling my helper method which will return String.
3) for each return string, I will append to CSVstring.

How can I achieve without hitting limitation.
I know it is really simple to write in Java, Now I am stuck on this simple loop.