[SalesForce] @future and triggers

I want to do a bulk update of records in parallel, but Batch Apex doesn't permit this.

I was wondering if the following solution would work:

  1. I have an SObject defined that holds a value for the query, limit & offset values.
  2. I split a job up according to a max say 1000 records and the correct offset and I add these values one at a time to the above table, which fires a trigger that calls an @future method.
  3. The @future method does all the processing.

Now the question I have is –

  1. Does the above scenario violate the @future invocation limit of 10 from the calling code? i.e. Does the trigger callout count towards the limit in the apex calling the insert record.

thanks

Best Answer

Well first let me clarify if i understand your idea right:

  1. You have custom object object
  2. On the insert of that object you have trigger
  3. in that trigger you have future call
  4. In Future call you are again inserting object(point 1) which in theory run recursively.

No, This will not work!

Why?

You can not call future method from another feature method in your case you are calling trigger and that is calling future method.

It will fail at second iteration as it will realize that you are calling future from future.

You cannot call a method annotated with future from a method that also has the future annotation. Nor can you call a trigger from an annotated method that calls another annotated method.

Best option is follow the advise given by cropredy in comment

Related Topic