+ Start a Discussion
dsh210@lehigh.edudsh210@lehigh.edu 

Avoiding DML Limit with 100+ objects

Hey all,

 

I just ran into an issue where in some cases I will need to insert more than 100 objects from a command button call on a visualforce page. I obviously cannot have 100+ insert calls, since that runs over the gov limit. However, can I get around this by inserting an array of objects or using some other method?

 

Thanks,

DH

MJ09MJ09

The easiest way to avoid hitting this kind of limit is to avoid doing individual insert statements. Instead, create an array or List of the SObjects you want to insert, then insert the whole List in a single insert statement.

 

Since you're using Visualforce, another alternative would be to use AJAX. Your Visualforce page could invoke an action method in your controller that inserts one object, then returns to the VF page. The VF page would display some kind of status indication, then use AJAX to call the action method again, which would insert the second object, and so on. That's more complicated to develop, but if it's important to you to give that kind of feedback to your users, it might be a viable approach.

 

If you use this AJAX approach, keep in mind that each insert operation would be a separate transaction. If you run into an error on, say, the 5th insert operation, you wouldn't be able to easily roll back the previous 4 inserts.

ca_peterson_oldca_peterson_old

Yep, you're limited to 100 DML (insert) calls, but 10,000 rows total per action. Put your objects into a list and insert the list and you're perfectly fine.