Skip to content

How to invoke the invoice run from outside Salesforce?

In certain cases, you may need to invoke the invoice run from outside Salesforce. To do so, you must make use of Salesforce's REST API, which allows for executing Apex code via REST calls.

Setting up support for this "remote control" in JustOn/Salesforce involves the following major tasks:

First, create a piece of Apex code to invoke the invoice run batch chain, like

// 1. Create a new Invoice Run record OR use an existing Invoice Run
ONB2__InvoiceRun__c invoiceRun = new ONB2__InvoiceRun__c(
    ONB2__PeriodEndDate__c = Date.newInstance(2018, 3, 1),
    ONB2__PeriodStartDate__c = Date.newInstance(2018, 3, 31)

    // === optional parameters: ===
    // ONB2__Filter__c
    // ONB2__TransactionFilter__c
    // ONB2__OpportunityFilter__c
    // ONB2__GenericFilters__c
    // ONB2__InvoiceDate__c
insert invoiceRun;

// 2. Start the Invoice Run batch chain
new ONB2.ChainRunner()
    new ONB2.ChainFactory().getByName('InvoiceRunChain')
        new Map<String, Object>{'invoiceRunId' => invoiceRun.Id} // Here you pass the Invoice Run Id

You can now

  • Call this code via the Tooling API using the executeAnonymous resource, as described in REST Resources in the Salesforce Developer Documentation, or
  • Implement this code in an Apex class and expose this class as a REST web service, as described in Exposing Apex Classes as REST Web Services in the Salesforce Developer Documentation.

▶ You can then create an external application that accesses your Apex code through the REST architecture.