For the complete documentation index, see llms.txt. This page is also available as Markdown.

SDBatch (Legacy)

SDBatch is intended to use if clients intends batching SD Jobs together to be created. The goal is to create the SD Job records individually with Start__c=false then use SDBatch to gather all SD Jobs created and run them in sync. As long as the client is able to place the base record IDs in a list to reference, they can use the following apex class as a reference point.

The following instructions are intended for creating a test SDBatch class and provide more insight how the application operates.

Instructions

To test SDbatch quickly, we designed a method similar to Mass Merge. The intention is to have the user choose records from a list view and pass them to the class to create the jobs and run SDBatch.

1

Create your APEX class

public class SDBatchTest {
    private ApexPages.StandardSetController stdSetController;

    public SDBatchTest(ApexPages.StandardSetController sscOther) {
        stdSetController = sscOther;
    }
    
    public PageReference createBatchTest() {
        String objectName = ApexPages.currentPage().getParameters().get('objectName');
        Boolean showHeader = ApexPages.currentPage().getParameters().get('showHeader') != 'false';

        List<SObject> selectedRecords = stdSetController.getSelected();
        if (Test.isRunningTest()) {
            selectedRecords = new List<SObject> { new Contact(LastName='Test') };
        }
       
        //This is responsible for the SDJob creation. Start__c must be set to False. 
        List<SDOC__SDJob__c> jobList = new List<SDOC__SDJob__c> {};
          for(SObject selectedRecord : selectedRecords) {
            SDOC__SDJob__c job =
            new SDOC__SDJob__c(SDOC__Start__c=false,
                              SDOC__Oid__c=String.valueOf(selectedRecord.get('Id')),
                              SDOC__ObjApiName__c=objectName,
                              SDOC__SendEmail__c='0',
                              SDOC__Doclist__c='[<TEMPLATE NAME or ID>]');
            jobList.add(job);
          }
          insert jobList;
        // This is part calls SDBatch and searches for jobs based on isSDJobQuery.        
        SDOC.SDBatch sdb = new SDOC.SDBatch();
        sdb.templatenameorid = '[<TEMPLATE NAME or ID>]';
        sdb.isSDJobQuery = true;
        //The query can be updated for to specify the batch requirements. 
        sdb.query = 'WHERE SDOC__Start__c=false AND SDOC__Status__c != \'Error\''; 
        sdb.batchSize = 10;
        sdb.executeBatch();

        return new PageReference('/');
    }
   
}
2

Create your Visualforce page

<apex:page standardController="[<OBJECTAPINAME>]" showHeader="false"
extensions="SDBatchTest"

recordSetVar="selected"
action="{!createBatchTest}">
</apex:page>
3

Add the button to the object's List View

Button URL:

/apex/SDBatch_Test?objectName=[<OBJECTAPINAME>]

Testing

  1. The user will select a set of records from the list view and click the SDBatch button.

  2. The SDJobs will be created with 0%, but will be completed as the Apex Job completes.

Additional Notes:

  • The batch can be tracked from Setup > Apex Jobs

  • The Apex Jobs page has a respective Batch Jobs page. This will provide more detail of each batch created such as Submitted/Completed Date and Elapsed Time.

Last updated

Was this helpful?