Prerequisite steps to create Salesforce jobs

About this task

Before you start to create Salesforce job definition with HCL Workload Automation, consider the following limitations:
  • The batch Apex classes (and related methods) that you want to run with the Salesforce plug-in, must be defined with global access level, in order to make them accessible by all Apex everywhere (the public access level is not enough).
  • At job definition time, only Salesforce batch Apex classes can be run. If you select a non-batch Apex class, the job fails.
To create a Salesforce job definition, you must complete the prerequisite steps that are listed in the following procedure.
  1. Register on Salesforce Server and ask for user ID and password.
  2. Log in to Salesforce Server.
  3. Create the following Apex classes that are needed for the communication between HCL Workload Automation and Salesforce Server. The HCL Workload Automation Apex classes must be defined outside any package.
    Class TWSListApexClass
    @RestResource(urlMapping='/TWSListApexClass/*')
    global with sharing class TWSListApexClass{
    //This Apex class exposes the TWSListApexClass REST service 
    //which returns a list of all known Batchable Apex classes.    
        @HttpGet
        global static List<ApexClass> doGet() {
          RestRequest req = RestContext.request;
          RestResponse res = RestContext.response;
          String fullName='';
          List<ApexClass> tempList = 
          [SELECT NamespacePrefix,Name FROM ApexClass ORDER BY Name];        
          List<ApexClass> result = new List<ApexClass>();
          for (ApexClass a: tempList){
           if (a.NamespacePrefix==null || a.NamespacePrefix.equals('')){
                fullName=a.Name;
               } else {
                 fullName=a.NamespacePrefix+'.'+a.Name;
               }
               System.debug(LoggingLevel.Info, 'ApexClass: '+fullName);            
               result.add(a);
            }   
            return result;
        }
    }
    Class TWSSubmitApexJob
    @RestResource(urlMapping='/TWSSubmitApexJob/*')
    global with sharing class TWSSubmitApexJob{
    //This Apex class exposes the TWSSubmitApexJob REST service 
    //which submits an Apex class to the Salesforce server.
        @HttpGet
        global static ID doGet() {
            RestRequest req = RestContext.request;
            RestResponse res = RestContext.response;
            String apexClass = req.params.get('className');
            System.debug(LoggingLevel.Info, 'Execute Batch:'+apexClass);
            Type t = Type.forName(apexClass);
            if (t == null){
               throw new TWSException (apexClass + ' not found');
            }         
            Object s = t.newInstance();
            ID batchprocessid = 
            Database.executeBatch((Database.Batchable<sObject>)s);
            System.debug(LoggingLevel.Info, 'Job ID: '+batchprocessid);
            return batchprocessid;
        }    
    global class TWSException extends Exception{}
    } 
    Class TWSMonitorApexJob
    @RestResource(urlMapping='/TWSMonitorApexJob/*')
    global with sharing class TWSMonitorApexJob{
    //This Apex class exposes the TWSMonitorApexJob REST service 
    //which will monitor the progress of the backend Apex job.
      @HttpGet
      global static AsyncApexJob doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        ID i = (ID) req.params.get('jobID');
        AsyncApexJob a = [SELECT Id, Status, ExtendedStatus, NumberOfErrors, 
        JobItemsProcessed, TotalJobItems FROM AsyncApexJob WHERE Id = :i];
        return a;
        }
    }
    Class TWSAbortApexJob
    @RestResource(urlMapping='/TWSAbortApexJob/*')
    global with sharing class TWSAbortApexJob{
    //This Apex class exposes the TWSAbortApexJob REST service 
    //which will abort the Apex job on the Salesforce server.    
        @HttpGet
        global static void doGet() {
            RestRequest req = RestContext.request;
            RestResponse res = RestContext.response;
            String jobID = req.params.get('jobID');
            System.abortJob(jobID);
        }
    }
  4. Verify the content of the Salesforce plug-in properties file:

    <TWA_HOME>\TWS\javaExt\cfg\<plug-in_name>.properties

    This file contains the plug-in properties that were set at installation time and that you can choose to override later. The plug-in properties are the following:
    ProxyServer
    ProxyServerPort
    pollingPeriod
    pollingTimeout
    where
    ProxyServer
    The IP address or the server name for the proxy server. Specify this property if you connect to the Salesforce server through a proxy server.
    ProxyServerPort
    The listening port of the proxy server.
    pollingPeriod
    The monitoring frequency. It determines how often the job is monitored during its execution. It is expressed in seconds.
    pollingTimeout
    The monitoring time. It determines for how long the job is monitored during its execution. At the end of the timeout interval, the job fails. It is expressed in seconds.
    The values that you specify in the properties file are the values that are used at job definition time.