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
TomSnyderTomSnyder 

Wierd Governor Limit issue when Updating via List View

 

I am getting 'Too many script statements: 10201'

 Governor Limit error when submitting ~100 or more updates at a time via the list view. 

 

When using the list view,  does it update in batch?  If so, according to the docs in the case of 100 records I should have 10,000 + (100*200) = 30,000 script statements allowed not 10200.  

 

If it's not updating in batch then why doesn't it happen when doing 1-50 updates?

 

Additional Details:

 All the updates performed were not data changes,  just a hit to have the trigger executed

 This is not an issue when doing a single update via the edit.

 or  less then 50 via the list view.

 or 200 via the API.

I Also updated all record (+250k) via the API wo/ any gov limit errors, This proves its not caused by a differences in the records data causing difference logic to be applied.

 


Tom

 

 


 

 

 

 

 

 


 

JustinCJustinC
Have you created any Apex triggers on the object you are updating?
TomSnyderTomSnyder

Yes,  here the code,  the Geography class is too large to paste but you can get the idea what im trying to accomplish.  My issue is not so much with the code  I could reduce the lines at the expense of reusablity but I would reather not go down that path.   My real issue is just that the gov limits for a List view update are handled differently then when doing a API call in batch or a single update via the UI.  So some insight of how gov limits for List view update are applied would be real helpful.

 

Another question I have been wondering is if the gov limits for triggers are for each trigger or the total for all triggers invoked.

 

 

trigger trigLeadCountryValidation on Lead (before insert, before update) { for (Lead l : Trigger.new ) { Geography.GeoAddress ga = new Geography.GeoAddress(l); if (ga.address.country != null) { ga.resolveCountryInfo(); if (ga.getCountryInfo() == null) { if (l.Lead_Country__c==null) { ga.writeTo(l); l.Lead_Country__c=null; } else //l.Lead_Country__c is not valid send error l.Lead_Country__c.AddError(Geography.ERR_INVALID_COUNTRY); } else ga.writeTo(l); } } }

 

JustinCJustinC

My real issue is just that the gov limits for a List view update are handled differently then when doing a API call in batch or a single update via the UI.  So some insight of how gov limits for List view update are applied would be real helpful.
>> When performing a field update through a list view, the SF.com engine will take all those updates and send them to the trigger once, as a list of objects. This is similar to uploading a file through the apex data loader. Your trigger must be written in such a way that it can successfully handle 200 lead insert/updates at a time, which is the max that would be sent to the trigger at a time.

Another question I have been wondering is if the gov limits for triggers are for each trigger or the total for all triggers invoked.
>> If you have multiple triggers on the Lead object I would imagine they all count against the governor limits. I believe it's more standard practice to have one trigger per lead, and then inside the trigger you'd call the different classes needed. As well, you can use Trigger.isInsert(), Trigger.isBefore(), etc. to only call relevant code in the right circumstances (see docs for more detail).

 

Without seeing the code of your Geography class, it's difficult to tell you exactly what your problem is, but I bet that if it has a lot of code, and that code is being called potentially up to 200 times (once per loop) in the trigger. You might want to consider writing your geography class in such a way that it can take a list of leads, and perform the necessary logic/updates/addError inside it without needing to be called over and over again.

 

I hope some of this helps.

TomSnyderTomSnyder

Justin, 

 

Thank you for the feedback.

 

But if the list view update is updated in a batch mode,  then why does the error not happen when doing API calls (such as the dataloader).   Also when updating in batch with a 200 records I should get 10,000 + (100*200) = 30,000 script statement limit. (as defined in the Apex gov limit section)  But,  I am limiting at 10200,  which is the limit for a single update.

 

Any clue?

 

 

 

 

JustinCJustinC

I guess that's a good question - you can confirm that an apex data loader update of, say 100 records, works fine, but updating those same 100 records in list view mode causes this error?

 

Also, just for debugging, do you know for certain how many script statements your geography class consumes per loop? You should be able to do a System.Debug at the beginning of the loop and at the end of the loop, and count the difference. See this page on how to debug governor limits:

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_limits.htm?SearchType=Stem

 

TomSnyderTomSnyder

it never completes the loop,  since it errors out once the limit is reached.

 

I did update the records via the 'Update Lead Status' button,  and saw that for a 100 records it used ~10650 script statements.  but that update  show the limit to be 30,000 as expected not 10200 as with a mass update using the list view.

 

 

 I attached condenced log to show that as you said they are handle in bulk however the script statement limits were treated a a single entry (10200).

 

Apex script unhandled trigger exception by user/organization: 00530000000xuHQ/00D3000000066BQ trigContactCountryValidation: execution of BeforeUpdate caused by: System.Exception: Too many script statements: 10201 Class.Geography: line 267, column 16 Class.Geography.GeoAddress.<init>: line 312, column 13 Class.Geography.GeoAddress.<init>: line 310, column 39 Trigger.trigContactCountryValidation: line 4, column 35 Debug Log: *** Beginning trigContactCountryValidation on Contact trigger event BeforeUpdate for 0033000000NjE20, 0033000000NjE21, 0033000000NjE23, 0033000000NjE25, 0033000000NjE27, 0033000000NjE28, 0033000000NjE2A, 0033000000NjE2C, 0033000000NjE2F, 0033000000NjE2G, 0033000000NjOHq, 0033000000NjRYn, 0033000000NjRYp, 0033000000NjRaQ, 0033000000NjRaf, 0033000000NjRag, 0033000000NjRaj, 0033000000NjRal, 0033000000NjRam, 0033000000NjRap, 0033000000NjRas, 0033000000NjRav, 0033000000NjRax, 0033000000NjRay, 0033000000NjRaz, 0033000000NjRbA, 0033000000NjRbE, 0033000000NjRbG, 0033000000NjRbH, 0033000000NjRdS, 0033000000NjRf2, 0033000000NjRf3, 0033000000NjRf4, 0033000000NjRfE, 0033000000NjRfF, 0033000000NjRfm, 0033000000NjRfo, 0033000000O9hx1, 0033000000O9hx2, 0033000000O9hx3, 0033000000O9hx4, 0033000000O9hx5, 0033000000O9hx6, 0033000000O9hxA, 0033000000O9hxD, 0033000000O9hxE, 0033000000O9hxF, 0033000000O9hxG, 0033000000O9hxI, 0033000000O9hxJ, 0033000000O9hxL, 0033000000O9hxM, 0033000000O9hxN, 0033000000O9hxO, 0033000000O9hxP, 0033000000O9hxR, 0033000000O9hxT, 0033000000O9hxW, 0033000000O9hxY, 0033000000O9hxf, 0033000000O9hxj, 0033000000O9hxl, 0033000000OACrH, 0033000000OACrI, 0033000000OACrJ, 0033000000OAD0X, 0033000000OAD0n, 0033000000OAD1X, 0033000000OAD7z, 0033000000OAD8f, 0033000000OAD8j, 0033000000OAD8k, 0033000000OAD8t, 0033000000OADAN, 0033000000OADR4, 0033000000OADTD, 0033000000OADU8, 0033000000OADUG, 0033000000OADUH, 0033000000OADUO, 0033000000OADUS, 0033000000OADUU, 0033000000OADUx, 0033000000OADVM, 0033000000OADVa, 0033000000OADXA, 0033000000OADXB, 0033000000OADXi, 0033000000OADXw, 0033000000OADZ6, 0033000000OADZR, 0033000000OADZl, 0033000000OADaL, 0033000000OADaW, 0033000000OADab, 0033000000OADag, 0033000000OADan, 0033000000OADar, 0033000000OADaz, 0033000000OADb1, 0033000000OADbI, 0033000000OADbN, 0033000000OADbY, 0033000000OADbb, 0033000000OADbc, 0033000000OADbi, 0033000000OADbl, 0033000000OADbp, 0033000000OADc0, 0033000000OADc2, 0033000000OADc7, 0033000000OADcA, 0033000000OADcL, 0033000000OADcQ, 0033000000OADcR, 0033000000OADcT, 0033000000OADca, 0033000000OADcb, 0033000000OADcm, 0033000000OADcr, 0033000000OADd4, 0033000000OADd5, 0033000000OADdA, 0033000000OADdE, 0033000000OADdP, 0033000000OADdQ, 0033000000OADdT, 0033000000OADdU, 0033000000OADdW, 0033000000OADdq, 0033000000OADeC, 0033000000OADeN, 0033000000OADeS, 0033000000OADeT, 0033000000OADeV, 0033000000OADeZ, 0033000000OADea, 0033000000OADeb, 0033000000OADec, 0033000000OADei, 0033000000OADeo, 0033000000OADf2, 0033000000OADf3, 0033000000OADfB, 0033000000OADfF, 0033000000OADfY, 0033000000OADfb, 0033000000OADff, 0033000000OADfk, 0033000000OADfl, 0033000000OADfw, 0033000000OADfz, 0033000000OADg0, 0033000000OADg1, 0033000000OADg2, 0033000000OADg3, 0033000000OADg4, 0033000000OADg5, 0033000000OADg6, 0033000000OADg7, 0033000000OADg8, 0033000000OADgG, 0033000000OADgX, 0033000000OADgY, 0033000000OADgg, 0033000000OADgh, 0033000000OADgi, 0033000000OADgj, 0033000000OADgo, 0033000000OADgr, 0033000000OADgs, 0033000000OADgt, 0033000000OADh6, 0033000000OADh7, 0033000000OADh8, 0033000000OADh9, 0033000000OADhA, 0033000000OADhB, 0033000000OADhC, 0033000000OADhD, 0033000000OADhE, 0033000000OADhF, 0033000000OADhH, 0033000000OADhI, 0033000000OADhJ, 0033000000OADhK, 0033000000OADhL, 0033000000OADhM, 0033000000OADhN, 0033000000OADhP, 0033000000OADhQ, 0033000000OADhR, 0033000000OADhU, 0033000000OADhV, 0033000000OADhW, 0033000000OADhX, 0033000000OADhY, 0033000000OADha, 0033000000OADhc, 0033000000OADhd 20090303163607.126:Trigger.trigContactCountryValidation: line 3, column 5: SelectLoop:LIST:SOBJECT:Contact 20090303163607.126:Class.Geography.Address.<init>: line 97, column 13: returning from end of method public void clear() in 0 ms 20090303163607.126:Class.Geography.Address.<init>: line 122, column 18: returning from end of method public Address<Constructor>(String, String, String, String, String) in 0 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 313, column 17: returning from end of method public Address<Constructor>(SOBJECT:Contact, Boolean) in 0 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 312, column 13: returning from end of method public GeoAddress<Constructor>(Geography.Address, String, String, String, String, Geography.LngLat, String, String) in 0 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 310, column 39: returning from end of method public GeoAddress<Constructor>(SOBJECT:Contact, Boolean) in 2 ms 20090303163607.126:Trigger.trigContactCountryValidation: line 4, column 35: returning from end of method public GeoAddress<Constructor>(SOBJECT:Contact) in 2 ms 20090303163607.126:Class.Geography.Countries.getCountries: line 532, column 13: SelectLoop:LIST:SOBJECT:Geography__c 20090303163607.126:Class.Geography.Countries.getCountries: line 532, column 35: SOQL query with 233 rows finished in 121 ms 20090303163607.126:Class.Geography.Countries.getCountries: line 532, column 13: 1 query more iteration, total execution: 45 ms 20090303163607.126:Class.Geography.Countries.getCountries: line 549, column 13: HEAP Countries Cost/LIMIT/Total Cost/Remaining 22207/100000/22726/77274 20090303163607.126:Class.Geography.Countries.getCountries: line 550, column 13: {AFGHANISTAN=Geography.Country:[A2=AF, A3=AFG, Aliases=null, Id=a1l300000004HKMAA2, name=AFGHANISTAN, region=EMEA, subregion=TMENA], ALAND ISLANDS=Geography.Country:[A2=AX, A3=ALA, Aliases=?LAND ISLANDS AALAND, Id=a1l300000004HKgAAM, name=ALAND ISLANDS, region=EMEA, subregion=WE], ALBANIA=Geography.Country:[A2=AL, A3=ALB, Aliases=null, Id=a1l300000004HHhAAM, name=ALBANIA, region=EMEA, subregion=CE], ALGERIA=Geography.Country:[A2=DZ, A3=DZA, Aliases=null, Id=a1l300000004HKLAA2, name=ALGERIA, region=EMEA, subregion=TMENA], AMERICAN SAMOA=Geography.Country:[A2=AS, A3=ASM, Aliases=null, Id=a1l300000004HJ3AAM, name=AMERICAN SAMOA, region=Asia Pacific, subregion=Other Asia Pacific], ANDORRA=Geography.Country:[A2=AD, A3=AND, Aliases=null, Id=a1l300000004HKiAAM, name=ANDORRA, region=EMEA, subregion=WE], ANGOLA=Geography.Country:[A2=AO, A3=AGO, Aliases=null, Id=a1l300000004HJnAAM, name=ANGOLA, region=EMEA, subregion=SSA], ANGUILLA=Geography.Country:[A2=AI, A3=AIA, Aliases=null, Id=a1l300000004HIAAA2, name=ANGUILLA, region=Latin America, subregion=Central America], ANTARCTICA=Geography.Country:[A2=AQ, A3=ATA, Aliases=null, Id=a1l300000004HJJAA2, name=ANTARCTICA, region=Latin America, subregion=South Cone], ANTIGUA AND BARBUDA=Geography.Country:[A2=AG, A3=ATG, Aliases=null, Id=a1l300000004HI9AAM, name=ANTIGUA AND BARBUDA, region=Latin America, subregion=Central America], ...} 20090303163607.126:Class.Geography.Countries.<init>: line 489, column 49: returning from end of method private void getCountries() in 200 ms 20090303163607.126:Class.Geography.GeoAddress.getCountryInfo: line 340, column 28: returning from end of method public Countries<Constructor>() in 200 ms 20090303163607.126:Class.Geography.GeoAddress.resolveCountryInfo: line 345, column 25: returning Geography.Country from method public Geography.Country getCountryInfo() in 200 ms 20090303163607.126:Class.Geography.GeoAddress.getCountryInfo: line 341, column 20: returning Geography.Country from method public Geography.Country getCountry(String) in 0 ms 20090303163607.126:Trigger.trigContactCountryValidation: line 6, column 19: returning Boolean from method public Boolean resolveCountryInfo() in 201 ms 20090303163607.126:Class.Geography.GeoAddress.writeTo: line 399, column 13: returning from end of method public void writeTo(SOBJECT:Contact, Boolean) in 0 ms 20090303163607.126:Class.Geography.GeoAddress.writeTo: line 397, column 41: returning from end of method public void writeTo(SOBJECT:Contact, Boolean) in 0 ms 20090303163607.126:Trigger.trigContactCountryValidation: line 15, column 17: returning from end of method public void writeTo(SOBJECT:Contact) in 0 ms 20090303163607.126:Class.Geography.Address.<init>: line 97, column 13: returning from end of method public void clear() in 0 ms 20090303163607.126:Class.Geography.Address.<init>: line 122, column 18: returning from end of method public Address<Constructor>(String, String, String, String, String) in 1 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 313, column 17: returning from end of method public Address<Constructor>(SOBJECT:Contact, Boolean) in 1 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 312, column 13: returning from end of method public GeoAddress<Constructor>(Geography.Address, String, String, String, String, Geography.LngLat, String, String) in 0 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 310, column 39: returning from end of method public GeoAddress<Constructor>(SOBJECT:Contact, Boolean) in 1 ms 20090303163607.126:Trigger.trigContactCountryValidation: line 4, column 35: returning from end of method public GeoAddress<Constructor>(SOBJECT:Contact) in 1 ms 20090303163607.126:Class.Geography.GeoAddress.getCountryInfo: line 340, column 28: returning from end of method public Countries<Constructor>() in 0 ms 20090303163607.126:Class.Geography.GeoAddress.resolveCountryInfo: line 345, column 25: returning Geography.Country from method public Geography.Country getCountryInfo() in 0 ms 20090303163607.126:Class.Geography.GeoAddress.getCountryInfo: line 341, column 20: returning Geography.Country from method public Geography.Country getCountry(String) in 0 ms 20090303163607.126:Trigger.trigContactCountryValidation: line 6, column 19: returning Boolean from method public Boolean resolveCountryInfo() in 1 ms 20090303163607.126:Class.Geography.GeoAddress.writeTo: line 399, column 13: returning from end of method public void writeTo(SOBJECT:Contact, Boolean) in 0 ms 20090303163607.126:Class.Geography.GeoAddress.writeTo: line 397, column 41: returning from end of method public void writeTo(SOBJECT:Contact, Boolean) in 0 ms 20090303163607.126:Trigger.trigContactCountryValidation: line 15, column 17: returning from end of method public void writeTo(SOBJECT:Contact) in 0 ms <!-- START LOOP *************

 

repeat until > 10200 script statements (too much to include)

*****************************************--> 20090303163607.126:Class.Geography.Address.<init>: line 97, column 13: returning from end of method public void clear() in 0 ms 20090303163607.126:Class.Geography.Address.<init>: line 122, column 18: returning from end of method public Address<Constructor>(String, String, String, String, String) in 1 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 313, column 17: returning from end of method public Address<Constructor>(SOBJECT:Contact, Boolean) in 1 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 312, column 13: returning from end of method public GeoAddress<Constructor>(Geography.Address, String, String, String, String, Geography.LngLat, String, String) in 0 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 310, column 39: returning from end of method public GeoAddress<Constructor>(SOBJECT:Contact, Boolean) in 1 ms 20090303163607.126:Trigger.trigContactCountryValidation: line 4, column 35: returning from end of method public GeoAddress<Constructor>(SOBJECT:Contact) in 1 ms 20090303163607.126:Class.Geography.GeoAddress.getCountryInfo: line 340, column 28: returning from end of method public Countries<Constructor>() in 0 ms 20090303163607.126:Class.Geography.GeoAddress.resolveCountryInfo: line 345, column 25: returning Geography.Country from method public Geography.Country getCountryInfo() in 0 ms 20090303163607.126:Class.Geography.GeoAddress.getCountryInfo: line 341, column 20: returning Geography.Country from method public Geography.Country getCountry(String) in 0 ms 20090303163607.126:Trigger.trigContactCountryValidation: line 6, column 19: returning Boolean from method public Boolean resolveCountryInfo() in 0 ms 20090303163607.126:Class.Geography.GeoAddress.writeTo: line 399, column 13: returning from end of method public void writeTo(SOBJECT:Contact, Boolean) in 0 ms 20090303163607.126:Class.Geography.GeoAddress.writeTo: line 397, column 41: returning from end of method public void writeTo(SOBJECT:Contact, Boolean) in 0 ms 20090303163607.126:Trigger.trigContactCountryValidation: line 15, column 17: returning from end of method public void writeTo(SOBJECT:Contact) in 0 ms <!-- END LOOP *************

 

repeat until > 10200 script statements

*****************************************--> 20090303163607.126:Class.Geography.Address.<init>: line 97, column 13: returning from end of method public void clear() in 0 ms 20090303163607.126:Class.Geography.Address.<init>: line 122, column 18: returning from end of method public Address<Constructor>(String, String, String, String, String) in 0 ms 20090303163607.126:Class.Geography.GeoAddress.<init>: line 313, column 17: returning from end of method public Address<Constructor>(SOBJECT:Contact, Boolean) in 0 ms System.Exception: Too many script statements: 10201 Class.Geography: line 267, column 16 Class.Geography.GeoAddress.<init>: line 312, column 13 Class.Geography.GeoAddress.<init>: line 310, column 39 Trigger.trigContactCountryValidation: line 4, column 35 Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 1 out of 20 Number of query rows: 233 out of 1000 Number of SOSL queries: 0 out of 0 Number of DML statements: 0 out of 20 Number of DML rows: 0 out of 100 Number of script statements: 10201 out of 10200 ******* CLOSE TO LIMIT Maximum heap size: 22496 out of 100000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 0 Number of System.runAs() invocations: 0 out of 0 Total email recipients queued to be sent : 0 Static variables and sizes: Geography:ERR_INVALID_COUNTRY:124 Geography:ERR_NULL_COUNTRY:51 Geography:IS_TESTMETHOD:4 Geography:LEVEL_COUNTRY:4 Geography:LEVEL_COUNTY:4 Geography:LEVEL_POSTAL:4 Geography:LEVEL_STATE:4 Geography:PREFERRED_PROVIDER:8 Geography:Utility:4 Geography:mapCountries:21964 Stack frame variables and sizes: Frame0 c:0

 

JustinCJustinC

If you do a debug right at the beginning of your trigger that outputs this:

Limits.getLimitScriptStatements()

 

Do you get a different script limit in each of these scenarios?

1) List View > Change Lead Status to 100 records

2) List View > Change a field value to 100 records (using in-line editing)

3) Apex Data Loader > Update 100 records (make sure batch size is set >= 100)

 

TomSnyderTomSnyder

>>Do you get a different script limit in each of these scenarios?

 

Yes

 

1) 30K

2) 10.2K

3) Not sure how to read the log when doing a API call,  but it works wo/ error so I can only assume it works as expected  (30K for 100, 50K for 200)

 

The issue as you can see by the last log is that bulk update using the List View in-line editing  are using the limits set for a single update.  FYI,  it looped ~83 times before failure,  so ~123 (10.2K/83) lines per update,  in the case of the sample used in the log all the countries were the same value so no difference in code branching for each record in the loop (except for the first one where instaniates the the static countries.)

 

RE:

 

 

Cumulative resource usage:

Resource usage for namespace: (default)

Number of SOQL queries: 1 out of 20

Number of query rows: 233 out of 1000

Number of SOSL queries: 0 out of 0

Number of DML statements: 0 out of 20

Number of DML rows: 0 out of 100

Number of script statements: 10201 out of 10200 ******* CLOSE TO LIMIT

Maximum heap size: 22496 out of 100000

Number of callouts: 0 out of 10

Number of Email Invocations: 0 out of 10

Number of fields describes: 0 out of 10

Number of record type describes: 0 out of 10

Number of child relationships describes: 0 out of 10

Number of picklist describes: 0 out of 10

Number of future calls: 0 out of 10

Number of find similar calls: 0 out of 0

Number of System.runAs() invocations: 0 out of 0

Total email recipients queued to be sent : 0

Static variables and sizes:

Geography:ERR_INVALID_COUNTRY:124

Geography:ERR_NULL_COUNTRY:51

Geography:IS_TESTMETHOD:4

Geography:LEVEL_COUNTRY:4

Geography:LEVEL_COUNTY:4

Geography:LEVEL_POSTAL:4

Geography:LEVEL_STATE:4

Geography:PREFERRED_PROVIDER:8

Geography:Utility:4

Geography:mapCountries:21964

 

 

JustinCJustinC

For #3, you could potentially send yourself an email containing the output of the Limits methods. Make sure to do it before the loop begins.

The class for sending email is: Messaging.sendEmail()

 

Maybe you've identified a legitimate issue in scenario #2. Perhaps it's worth contacting Salesforce support (you'll have to be really clear with them that you think you've identified an issue, otherwise they'll just tell you they don't support custom apex code).

 

Good luck!

TomSnyderTomSnyder

Thanks for your help,  I did send in a case and now after that last log I do think is a legitimate issue,  Im just surprised it has not come up before because its not just script statements it seems to be all limits don't scale when using inline edits via the list view.

 

I will post back their findings.

 

Later,

 

-Tom

 

Simon_FranceSimon_France
Hello, old post but it seems to me that Salesforce is still handling inline editing differently than a batch edit.
Did you find an answer ?