function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chiranjeevi ReddyChiranjeevi Reddy 

How to Submit records for approval in bulk?

For example let's take contact records, I can submit one record for approval using the approval process, also trying to submit records through apex calss but it only works with single records . Is there any other way to submit records for approval in bulk?

Could you help me in this requirement!
Thanks
Best Answer chosen by Chiranjeevi Reddy
Amit Chaudhary 8Amit Chaudhary 8
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());
    }
http://shivasoft.in/blog/salesforce/dynamic-approval-process-based-on-the-apex-and-trigger/
http://releasenotes.docs.salesforce.com/en-us/spring15/release-notes/rn_forcecom_process_visually_automate.htm#rn_forcecom_visually_automate

Please let us know if this will help you

Thanks
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
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());
    }
http://shivasoft.in/blog/salesforce/dynamic-approval-process-based-on-the-apex-and-trigger/
http://releasenotes.docs.salesforce.com/en-us/spring15/release-notes/rn_forcecom_process_visually_automate.htm#rn_forcecom_visually_automate

Please let us know if this will help you

Thanks
Amit Chaudhary
This was selected as the best answer
Fiona QuickFiona Quick
Is there a lightning version of this Apex/Solution?
Leonardo MonsalvoLeonardo Monsalvo
Hola, muchas gracias, esto ha sido de gran ayuda!!!