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
kzmpkzmp 

Before update and before insert triggers and batch updates

Hi,

I have a before update and before insert trigger which for each records checks whether the record has modified its address and marks it as modified if yes.

The trigger works fine until a batch update of all records is performed in which case I get the following error:

 

System.LimitException: XXXX:Too many script statements: 12801

the question I have is how to either make the trigger to run in batch jobs but not throw that error OR how to disable the trigger in code (doing that manually is not an option) before the batch job is being run.

 

Thanks,

Kos

Duncan_IdahoDuncan_Idaho

You can enclose the trigger code in something like:

 

 

If(trigger.new.size()==1){

...

}

 

Then your code would only run when a single object was being updated.

 

kzmpkzmp

Thanks a lot.

If there is no other way I will definately use this.

 

Is there a way to make the trigger just work why am I getting this exception?

 

I would preferen to have the trigger on for all objects as I use the trigger to maintanin whether an address has changed or not. I mean there could be an external batch application which updates the addresses in which case my validation will not work.

 

Thanks,

Kos

Duncan_IdahoDuncan_Idaho

If you post the trigger, I'll take a look.

kzmpkzmp

Hi Duncan,

Thanks for trying to help out.

The trigger code is:

 

trigger Account_CA_BIBU on Account(before insert,before update) {
    RecordStatusSetter.InvokeRecordStatusSetter(trigger.new,trigger.old,trigger.IsInsert);
}

 

What the InvokeReocrdStatus setter does is the following in pseudo code:

1. Check the size of Trigger.New

2. Bring some data from an sObject (at most 4 rows selected the table has 6 rows altogether). Part of the selected items is XML which which gets parsed and convered into an object. The xml is aslo fairly small.

3. Loop through each record in Trigger.New and find out if it is an update or insert. If it is an update find out if certain fields have been modified and if yes set a status field to modified. If it is insert set the status field as modified.

 

That is all there is.

I am guessing that even though I do my batch commits in batches of 2000 SalesForce groups them and sends a too large batch job and the records are too many in step number 3 above.

What do you think?

 

Thanks,

Kos