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: - The tax calculation using Avalara AvaTax must be enabled in your org before you can use this service. For more information, see the Order and Inventory Management Help.
- Due to a limitation, set the maximum batch size to 1 for optimal efficiency.
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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);
}
SCMC.InvoicingTaxCalculationBatch taxBatch = new SCMC.InvoicingTaxCalculationBatch();
taxBatch.invoiceIds = invoiceIds;
Id batchJobId = Database.executeBatch(taxBatch, 1 );
|
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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);
}
SCMC.InvoicingTaxCalculationBatch taxBatch = new SCMC.InvoicingTaxCalculationBatch();
taxBatch.invoiceIds = invoiceIds;
Id scheduledJobId = System.scheduleBatch(taxBatch, 'Calculate Tax for Invoices using AvaTax' , 60 , 1 );
|
Properties
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
|