1

The project I am working on is using Communities and at a specific point in a business process we need to (in sequential order) enable a contact as a partner user, update the user record, update the contact record, add the user to a public group, add a record in the AccountShare object, and once all of this is done - send an email to the new user. The requirements / design that got us to this point not withstanding (since I suspect at least one person will ask why we're doing all of this :-), our problem is that the above activities trigger the "Mixed DML" error, so we have moved to an @future and batch approach. While we have beaten the Mixed DML issue, now the problem is that it takes minutes+ for the email to go out, and the users are not happy. I was skimming the Winter '15 release notes and read about Queueable Chaining.

My question, then, is: Can Queueable Chaining be used to address a Mixed DML error?

1 Answer 1

1

You could use either the batchable interface or queueable interface. Here's a batchable interface implementation:

global class CommunityProcess implements Database.Batchable<ProcessItem> {
    interface ProcessItem {
         void doAction(Id recordId);
    }
    public class Phase1 implements ProcessItem {
        public void doAction(Id recordId) {
            // Implementation omitted
        }
    }
    public class Phase2 implements ProcessItem {
        public void doAction(Id recordId) {
            // Implementation omitted
        }
    }
    global Id recordId;
    global void CommunityProcess(Id recordId) {
        this.recordId = recordId;
    }
    global Iterable<ProcessItem> start(Database.BatchableContext context) {
        return new ProcessItem[] { new Phase1(), new Phase2() };
    }
    public void execute(Database.batchableContext context, ProcessItem[] scope) {
        scope[0].doAction(recordId);
    }
    public void finish(Database.batchableContext context) {
        // Clean up
    }
}

It can be called like this:

Database.executeBatch(new CommunityProcess(someRecordId), 1);

As a queueable interface, you'd need a number of top-level classes to implement each phase, but the process would be similar in nature. Note: in a developer edition, there's a maximum of 5 chains (the initial parent, plus four children, in order).

Also note, this code isn't tested, so you might need to tweak the code a bit to achieve your specific goals.

0

You must log in to answer this question.

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