+ Start a Discussion
sparktestsparktest 

trying to add multiple child records when parent object is updated/added

 

Does anyone have any examples of doing this, or can they point to a good example?  I am trying to use a bulk List insert to load a child object per a specific update/insert to the parent object.  I am presently successful, so long as there are 100 records or less.  If I go over 100 records, it gives me a DML error, though I am using the bulk insert as told to.

 

I can find update examples that are similar, but so far nothing that matches what I am trying to do....which doesn't seem to be anything that would be odd.  Mainly I just want to confirm that what I am trying to do is even possible, so if not, I can look into something else.

 

Can I load/update more than 100 records on a child object based on an update/insert of a parent Object?

 

Thank You For ANY help on this.

 

 

aalbertaalbert

Try using the @future annotation and doing the DML insert(s) in the apex method defined as @future. That apex method will run asynchronously, but the governor limits will let you insert many more records than if you perform this synchronously (as you are doing it now).

 

 

sparktestsparktest

aalbert,

Thanks, that is what I am trying to do, here

 

 http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=12808&view=by_date_ascending&page=2

 

I have the code there for the @future that is giving me fits as well.

 

I would like to confirm, however, if the limits I am hitting on the DML are correct.  I have had many tell me I should be fine with 120 records using a bulk insert....is that true or not?    The code shows that as well.

 

I am rewriting this code to simplify/test it for exactly if I need the @future and how to use it if I do, but could use any help I can get.

 

Thanks,

JustinCJustinC

See the docs on governor limits:

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

 

It sounds like you're running up against this limit:

Total number of records processed as a result of DML statements

 

When performing DML operations inside the context of a trigger, you're limited to 100 records processed as a result of DML statements (insert/update/etc).

 

However, if you write a class using @future (as noted above), that limit increases to 10,000 records processed. Since this class executes asynchronously, there are things to consider but it sounds like this might be the route you need to go down.

sparktestsparktest

Thanks Justin,

 

If you could PLEASE, take a look at the code I have in the link above.  The @future is giving me @fits and I cannot seem to get it to work.  I am getting the 'cannot call @future from @future method' error, or something like that, and even when I remove the @future the insert method still does not seem to do anything.

 

Any help would be greatly appreciated.......my eyes are killing me....

HarmpieHarmpie
I have posted the solution to the @future issue in your thread (the other 1) already.