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
Kavya Reddy 33Kavya Reddy 33 

How to invoke/trigger a salesforce batch class from a SAP system?

Deepak_KumarDeepak_Kumar

Hi Kavya,
If you want to invoke a batch class from the SAP system then you can have to integrate the SAP with Salesforce.
Where you will send any sample request to salesforce and salesforce will call the batch class with the help of web service.

Here are the some references :
https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_webservices
https://jayakrishnasfdc.wordpress.com/2018/09/09/apex-rest-web-services-example/

@RestResource(urlMapping=’/ExecuteBatch/*’)
global with sharing class MyRestResource {
  @HttpGet
   global static Account callBatch() {
           // Add your code
          //Call Batch Class here.
     }
     
}

Hope this helps you.

Thanks
Deepak
Kavya Reddy 33Kavya Reddy 33
Hi Deepak,

Thanks for your response.
I tried as per the code you mentioned. Since this batch class is all about sending emails what shoud be the return type of the Method?


@RestResource(urlMapping='/ExecuteBatch/*')
global with sharing class MyRestResource {
  @HttpGet
   global static <Object> callBatch() {
              BMC_SendEmailToDistributorContact sendEmail= new BMC_SendEmailToDistributorContact();
            database.executeBatch(sendEmail,1);

     }
     
}
Deepak_KumarDeepak_Kumar

Hi Kavya,
There is no need for return type when you call a batch class. It's asynchronous execution. IF you want you can send an email or update or insert a record in the finish method of the batch. So you can get an update when the batch will be finished.

Thanks.