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

problem in inserting in a batch when trigger called


I am able to add records in salesforce object one by one  when the trigger is enabled.
But I am not able to add records in salesforce object in batch when the trigger is enabled.
So is it possible to work with both or there is other workaround?


Triggers have very tight governing limits, and it seems like your trigger is exceeding those limits.  Can you send in the error message that you get, so that we know if that is the case?

If that is the case, then I think that you have some SOQL or DML being executed in the for loop.  Try using queries and DML in batches instead of doing them inside the loop - putting them in the loop will mostly make the batch trigger fail.  I hope this helps.


Also, You are looping throught the trigger objects, right?
Something like this:
    for (Integer i = 0; i <; i++) {
        String sName =[i].Name;
If you are not looping through them then obviously you are going to have some behavioral issues.
Thanks for the reply.
Actually I am not grtting any error. But the records are not inserted in salsforce. I am inserting record through java code ws-api. I am doing that in batch. but I have just came to know that when my batch size is greater than 10, trigger fails.
So this is my problem.
Thanks for the reply
but my problem is I am not looping for trigger object, I am adding objects in a batch. And on beforeInsert this trigger is called.
Maybe if you post some, or all, of the code we can see what's wrong at a glance.