9

I've got code to create and submit for approval a custom object. I'm running into the DML statement limit.

As far as I can see each record I submit for approval takes up a DML statement, but there's no option to submit in bulk.......

Am I missing something?

1 Answer 1

12

You can submit multiple Records for approval, sample code below.

List<Approval.ProcessSubmitRequest> requests = new List<Approval.ProcessSubmitRequest> ();
     for (Id oppId: opportunities) {
                    Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
                    req1.setComments('Submitting request for approval ');
                    req1.setObjectId(oppId);
                    requests.add(req1);
        }


      Approval.ProcessResult[] processResults = null;
                try {
                    processResults = Approval.process(requests, true)
    }catch (System.DmlException e) {
        System.debug('Exception Is ' + e.getMessage());
    }
4
  • Thanks @techtrekker! Couldn't see this in the docs. Just a note that you need to create the variable requests, something like: list<Approval.ProcessSubmitRequest> requests = new list<Approval.ProcessSubmitRequest>();
    – ChrisN
    Commented Oct 12, 2012 at 10:48
  • Absolutely, missed writing the declaration. Commented Oct 12, 2012 at 11:01
  • perhaps you could update your answer ;) Commented Oct 12, 2012 at 11:07
  • My thoughts exactly.... done ! :) Commented Oct 12, 2012 at 11:13

You must log in to answer this question.

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