How to invoke the invoice run from outside Salesforce?
← Salesforce Environment FAQ ← Billing & Invoice Management FAQ
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:
(1) 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()
.execute(
new ONB2.ChainFactory().getByName('InvoiceRunChain')
.setParameters(
new Map<String, Object>{'invoiceRunId' => invoiceRun.Id} // Here you pass the Invoice Run Id
)
);
(2) 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.
(3) You can then create an external application that accesses your Apex code through the REST architecture.