+ Start a Discussion
Dylan MadisettiDylan Madisetti 

System.LimitException 200001?? To many Scripts? Salesforce you crazy

Hey there,

I'm trying to build a column graph using the google charts API. However, whenever I run my apex 
this:
System.LimitException: Too many script statements: 200001
pops up.

Normally this would call for more concise code right? However my script isn't all that long. I get that I have a few loops and a soql statment (but it's just a count and since I'm using the sand box, it should return just 1) inside said loops, however it doesn't seem to me that they should pull an error. Any suggestions?

Here's my Apex:

public class tv_dashboard_class {

    public Integer getWins { get; set; }

    public String getDay { get; set; }

//initialize
                Date day = Date.today();
                Integer dd = 0; //Day Displacement
                Integer DayVal = 0;
                Integer d = 0;
                Integer[] val = new Integer[9]; //array of values for respective days
                Integer[] wins = new Integer[9];
                Date[] days = new Date[9]; // array of respective days
                String[] daynames = new String[9];


    public tv_dashboard_class() {
                {for ( d = 0; d <= 9;){
                    day = Date.today().addDays(-d-dd);
                    DayVal = day.toStartofWeek().daysbetween(day);
                    
                    //So not weekend
                    if ( (6 > DayVal) && (DayVal > 0) ){
                       wins[d] = [SELECT count() FROM Account  WHERE Account_Status__c = 'Lead' AND Interested_Stage_Date__c = :day];
                       val[d] = DayVal;
                       daynames[d] = Workdays(DayVal);
                       d++;
                    }else{ //if is weekend find nearest Friday
                        Integer i = 0; //arbitrary counter
                        while ( DayVal != 5){
                            i++;
                            day = date.today();
                            day = day.addDays( - d - dd -i);
                        }
                        dd += i;
                    }
                }}
    }
 
 
            //Weekday Switch
            public String Workdays( integer dayVal){
                if (dayVal == 1) return ('Monday');
                if (dayVal == 2) return ('Tuesday');
                if (dayVal == 3) return ('Wednesday');
                if (dayVal == 4) return ('Thursday');
                if (dayVal == 5) return ('Friday');
                return 'Invalid Date';
            } 
            
//...trying to get the top to work first

 


Here's the and Here's my Visualforce/JS (thought I'm sure it's alright)

<apex:page showheader="false" standardStylesheets="false" controller="tv_dashboard_class" >
    <head>
        <!--Load Google API-->
        <script type='text/javascript' src='https://www.google.com/jsapi' />
        <script src="/soap/ajax/19.0/connection.js" type="text/javascript" />
        
        <!--AJAX for APEX -->
        <script src="/soap/ajax/15.0/connection.js" type="text/javascript" />
        <script src="/soap/ajax/15.0/apex.js" type="text/javascript" />

        <!-- Jquery for Animation and what not -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript" />
        
        <!--TODO: Make JS Static Resource-->
        <script>
            // Project: TV Dashboard
            // Description: Create beautiful charts using the Google Charts API for Coporate TV
            // Start: Oct 8th 2012
            // End:
            
            //$o as not to get confused with Apexs Global
            j = jQuery.noConflict();
            
            google.load("visualization", "1", {packages:["corechart"]});
            
            j(document).ready(function(){
                   
                // New Google Chart Object
                var gChart = new google.visualization.DataTable();
                var graph = new google.visualization.ColumnChart(document.getElementById('chart_div'));
                
                // X Axis
                gChart.addColumn('string', 'Day');
                // Y Axis
                gChart.addColumn('number', 'Total Wins');
                
                drawChart();
                //drawChart();
                function drawChart() {
                    google.visualization.events.trigger(this, 'select', {});
                    graph.draw(gChart, {width: 2000, height: 1000, title:'Wins this Week', legend:'none',
                    vAxis: {minValue:0}, hAxis: {slantedTextAngle:45}, animation:{duration: 3000,easing:'out'}});            
                }
                
                
                for (v = 0; v < 10; v++ ){                     
                   gChart.addRow([" ", 0]);
                }
                drawChart();
                
                for (v = 0; v < 10; v++ ){                     
                   gChart.addRow([{!getDay},{!getWins}]);
                   drawChart();
                }
            });
            
        </script>
    </head>
    
    <body>
        <div id="chart_div" />
    </body>
</apex:page>

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Dylan MadisettiDylan Madisetti

Ahhh my in my while i never change DayVal while >.<

Sorry.. Was Stupid

All Answers

SammyComesHereSammyComesHere
In the below code, If it goes into else Bloxk , the counter d never increments hance may be the issue.


public class tv_dashboard_class { public Integer getWins { get; set; } public String getDay { get; set; } //initialize Date day = Date.today(); Integer dd = 0; //Day Displacement Integer DayVal = 0; Integer d = 0; Integer[] val = new Integer[9]; //array of values for respective days Integer[] wins = new Integer[9]; Date[] days = new Date[9]; // array of respective days String[] daynames = new String[9]; public tv_dashboard_class() { {for ( d = 0; d <= 9;){ day = Date.today().addDays(-d-dd); DayVal = day.toStartofWeek().daysbetween(day); //So not weekend if ( (6 > DayVal) && (DayVal > 0) ){ wins[d] = [SELECT count() FROM Account WHERE Account_Status__c = 'Lead' AND Interested_Stage_Date__c = :day]; val[d] = DayVal; daynames[d] = Workdays(DayVal); d++; }else{ //if is weekend find nearest Friday Integer i = 0; //arbitrary counter while ( DayVal != 5){ i++; day = date.today(); day = day.addDays( - d - dd -i); } dd += i; // Here you need to increment the counter. Counter d is never incrementing in else block } }} } //Weekday Switch public String Workdays( integer dayVal){ if (dayVal == 1) return ('Monday'); if (dayVal == 2) return ('Tuesday'); if (dayVal == 3) return ('Wednesday'); if (dayVal == 4) return ('Thursday'); if (dayVal == 5) return ('Friday'); return 'Invalid Date'; } //...trying to get the top to work first
Dylan MadisettiDylan Madisetti

Counter d is not supposed to increment in the else block. That way I get 10 week days. It worked in js. But maybe something was lost in translation. I'll debug to see whether it gets stuck in a infinite loop.

Dylan MadisettiDylan Madisetti

Ahhh my in my while i never change DayVal while >.<

Sorry.. Was Stupid

This was selected as the best answer