1

Question is in the title. For context, when a certain record is added, we would like to create a role (named after that record) and share it with that newly created role. Because of that, the flow ends up DML -> System DML -> DML. Since I would otherwise get a 'Mixed DML' error, that middle one needs to be separated with an @future. Unfortunately I need the third part of that to run in sequence but I cannot call one @future from another one. How can I go about doing this?

2 Answers 2

1

With Winter '15 you can use the Queueable interface to design an asynchronous job to be run, and which can kick off other asynchronous jobs. Original Salesforce Engineering Post on Queueable

Queueable in Winter '15 has a limited depth of 2 jobs, which should meet your needs if your initial record is created in real-time. Otherwise Spring '15 is introducing infinite job-chaining if you can wait a couple weeks.

A word of caution for your Apex tests. There is a known issue related to the use of System.enqueueJob() that causes most/all tests run afterwards to fail. This sounds like it's addressed in Spring '15. Also, the use of Queueable still counts against the daily limits for asynchronous executions.

3

Do you need this in real-time ? Otherwise you could create an action table and a batch job that perform the last part.

Kind regards,

Rudy De Coninck

1
  • That is a possible route, however there is the chance that these objects could be inserted in quick succession but not in a batch, meaning I could spawn a large number of batch jobs in a short time. Could I come up against limits with this idea? Jan 29, 2015 at 20:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .