Advanced Approval – Submit Multiple Records in Related List (Classic)

A new Code Using Advance Approvals

If you created a new approval process with Advanced Approvals package and you need a quick way to submit for approval multiple records from selecting them from a Related list (without having to enter each record), this code will work very well for you.

For this Project we have the Advance Approval in SBQQ__QuoteLine__c Object and the final behavior is that from the quote we can select the quote lines and send them for approval.

We are going to create a button of type List Button (JavaScript):

1. Creare a New Apex Class: Setup –> Click on your Name –> Developer Console AutoSubmit

global class AutoSubmit{
    webService static void processAutoSubmission(Id QLId){
     //In each quote line
     //Set<string> QLineIds = new Set<string>();
     //QLineIds.add(QLId);
//Call the Submit package class
     SBAA.ApprovalAPI.submit(QLId, SBAA__Approval__c.Quote_Line__c);
    }}

2. Create a New Button: Setup –> Objects –> Quote Line –> New Button or Link

  • Label: Test – Submit
  • Display Type: List Button
  • Display Checkboxes (for Multi-Record Selection): TRUE
  • Behavior: Execute JavaScript
  • Content Source: OnClick JavaScript
  • Body:
{!REQUIRESCRIPT("/soap/ajax/48.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/48.0/apex.js")}
var selectedLines = {!GETRECORDIDS($ObjectType.SBQQ__QuoteLine__c)};
var linesForUpdate = [];
if(selectedLines[0] == null){
   alert("You must select at least one record");
}else{
    for(var i = 0; i<selectedLines.length; i++){
       
       var quoteLin = sforce.SObject("SBQQ__QuoteLine__c");
       var quoteLin = selectedLines[i];
       quoteLin.Id = selectedLines[i];

       var message = sforce.apex.execute("AutoSubmit","processAutoSubmission",{QLId:quoteLin});
    }
}
location.reload(true);

3. Add the List Button in the Quote Page Layout in the Quote Line related list:
Setup –> Objects –> Quote –> Page Layout –> Quote Line Related List –> Button for Properties

Save.

Final Behavior: What you should observe at the end is the button available in the related list and the checkboxes for you to select the lines that you are going to send for approval.

One thought on “Advanced Approval – Submit Multiple Records in Related List (Classic)

  1. This looks great. But If we select more than 5 records it will hit us the governor limit of 101 SOQL… Is there any workaround for submitting more than 5 records?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.