SCM Apex API Developer Reference

scmc.InvoicingTaxCalculationBatch

global with sharing class InvoicingTaxCalculationBatch implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful

Enables you to calculate tax using Avalara for multiple invoices in a batch job.
You can provide a list of IDs representing the invoices that you want to calculate tax for. Once tax is calculated, you will receive an email with the number of successfully processed invoices and the number of errors. The errors are also stored in your org as error log records (SCMC__Error_Log__c).
Note that tax calculation using Avalara AvaTax must be enabled in your org before you can use this service. For more information, see the SCM Help.
This class implements the Salesforce Database.Batchable class. This enables you to:

  • Use the Database.executeBatch method to run the batch job.
  • Use the System.scheduleBatch method to schedule the batch job to run once at a future time.
For more information about using batch Apex, see the Salesforce developer documentation.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

// Retrieve the IDs of the invoices that you want to calculate tax for.
List<Id> invoiceIds = new List<Id>();
List<SCMC__Invoicing__c> invoices = 
    [SELECT Id FROM SCMC__Invoicing__c 
       WHERE SCMC__Shipping__r.SCMC__Status__c='Shipment complete'
       AND SCMC__External_Tax_Status__c = 'Not Calculated'];
for (SCMC__Invoicing__c invoice : invoices) {
    invoiceIds.add(invoice.Id);
}

// Create an instance of the class.
SCMC.InvoicingTaxCalculationBatch taxBatch = new SCMC.InvoicingTaxCalculationBatch();

// Set the list of IDs.
taxBatch.invoiceIds = invoiceIds;

// Call the Database.executeBatch method with the instance 
// and a scope size.
Id batchJobId = Database.executeBatch(taxBatch, 10);

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

// Retrieve the IDs of the invoices that you want to calculate tax for.
List<Id> invoiceIds = new List<Id>();
List<SCMC__Invoicing__c> invoices = 
    [SELECT Id FROM SCMC__Invoicing__c 
       WHERE SCMC__Shipping__r.SCMC__Status__c='Shipment complete'
       AND SCMC__External_Tax_Status__c = 'Not Calculated'];
for (SCMC__Invoicing__c invoice : invoices) {
    invoiceIds.add(invoice.Id);
}

// Create an instance of the class.
SCMC.InvoicingTaxCalculationBatch taxBatch = new SCMC.InvoicingTaxCalculationBatch();

// Set the list of IDs.
taxBatch.invoiceIds = invoiceIds;

// Schedule the batch to start in 60 minutes
// with a specific label and a scope.
Id scheduledJobId = System.scheduleBatch(taxBatch,'Calculate Tax for Invoices using AvaTax',60,10);

Properties

Name Type Description
invoiceIds List<Id> IDs of the invoices that you want to calculate tax for.
totalSuccess Integer Total number of invoices that the tax was successfully calculated for.
totalErrors Integer Total number of invoices that the tax could not be calculated for.

Methods

start

global Database.QueryLocator start(Database.BatchableContext context)

Do not call this method directly. Pass the instance of the class to Database.executeBatch or System.scheduleBatch instead.

execute

global void execute(Database.BatchableContext context, List<SObject> invoices)

Do not call this method directly. Pass the instance of the class to Database.executeBatch or System.scheduleBatch

finish

global void finish(Database.BatchableContext context)

Do not call this method directly. Pass the instance of the class to Database.executeBatch or System.scheduleBatch

© Copyright 2009–2022 FinancialForce.com, inc. All rights reserved. Various trademarks held by their respective owners.