Find your content:

Search form

You are here

Submit records for approval in bulk without hitting DML Statement limit

 
Share

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?


Attribution to: ChrisN

Possible Suggestion/Solution #1

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());
    }

Attribution to: techtrekker
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/2244

My Block Status

My Block Content