c2g.SalesInvoiceEInvoicingServiceglobal with sharing class SalesInvoiceEInvoicingService API methods for sending a sales invoice via the configured electronic invoicing provider. Sending a sales invoice will update the record to set fields used for tracking the progress and make a callout to the configured electronic invoicing provider. Because of platform restrictions around making callouts, there are multiple API methods covering different parts of this process to allow you to split the work across multiple execution contexts as needed. Methods
sendAsyncglobal static c2g.SalesInvoiceEInvoicingService.SendAsyncResponse sendAsync(Set<Id> salesInvoiceIds) Performs all operations needed to send electronic invoices from sales invoices. The sales invoices will be updated synchronously to mark them as sending, and a queueable will be started that makes the callout to the electronic invoicing provider asynchronously. Because this method starts a queueable, take care using it from code that may be called from a batch or queueable process where there are tight limits on the number of queueables that can be started. Consider using the `prepareToSend` and `sendPreparedInvoices` methods instead. Input Parameters
Return ValueAn object containing the ID of the AsyncApexJob started by this method. 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. Set<Id> salesInvoiceIds = new Set<Id>{ 'XYZ' }; SalesInvoiceEInvoicingService.SendResponse result = SalesInvoiceEInvoicingService.sendAsync( salesInvoiceIds ); Id asyncApexJobId = result.AsyncApexJobId; //Checking results in another execution context AsyncApexJob job = [ SELECT Status, ExtendedStatus, CompletedDate FROM AsyncApexJob WHERE Id = :asyncApexJobId ]; prepareToSendglobal static c2g.SalesInvoiceEInvoicingService.PrepareToSendResponse prepareToSend(Set<Id> salesInvoiceIds) Updates sales invoices to prepare them for sending. The invoices will be marked as sending and their Electronic Invoice Unique Identifier fields will be set if they have not been already. This method will not send the electronic invoices to the electronic invoicing provider. That must be done separately using either `send` or `sendPreparedInvoices`. Input Parameters
Return ValueAn object containing information about the execution of the request. sendPreparedInvoicesglobal static c2g.SalesInvoiceEInvoicingService.SendResponse sendPreparedInvoices(Set<Id> salesInvoiceIds) Turns sales invoices into electronic invoices and sends them to the electronic invoicing provider immediately. This method will make a callout for each sales invoice that it is given, so make sure that it is only called in an execution context that allows callouts. Invoices submitted to this method must be prepared for sending first, using the `prepareToSend` method. Input Parameters
Return ValueAn object containing information about the execution of the request. 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. public class ExistingProcess implements Queueable { public void execute(QueueableContext context) { System.enqueueJob(new ChainedJob()); Set<Id> salesInvoiceIds = new Set<Id>{'XYZ'}; //Cannot make a callout or start a queueable from this process, so we can only prepare invoices to send SalesInvoiceEInvoicingService.prepareToSend(salesInvoiceIds); } } //Separate batch job to send invoices after they have been prepared. Note how this is configured to //allow callouts. public class SendPreparedInvoices implements Database.Batchable<SObject>, Database.AllowsCallouts { public Database.QueryLocator start(Database.BatchableContext ctx) { return Database.getQueryLocator('SELECT Id FROM c2g__codaInvoice__c WHERE c2g__EInvoiceDeliveryStatus__c = \'Sending\''); } public void execute(Database.BatchableContext ctx, List<SObject> records) { Set<Id> salesInvoiceIds = new Map<Id, SObject>(records).keySet(); SalesInvoiceEInvoicingService.sendPreparedInvoices(salesInvoiceIds); } public void finish(Database.BatchableContext ctx) { } } validateSalesInvoicesglobal static c2g.SalesInvoiceEInvoicingService.ValidationResponse validateSalesInvoices(Set<Id> salesInvoiceIds) Returns information about the validity of the sales invoices for sending as electronic invoices. For example if the sales invoice status is not Complete or the delivery status is already Delivered. Input Parameters
Return ValueAn object containing information about the validity of the sales invoices. c2g.SalesInvoiceEInvoicingService.EInvoicingResponseglobal abstract with sharing class EInvoicingResponse Abstract base class that all other e-invoicing response classes extend. Customers are not expected to extend this themselves, but you can refer to other responses using this type to build common error-handling code. Provides a map of errors by record id. Properties
c2g.SalesInvoiceEInvoicingService.SendAsyncResponseglobal with sharing class SendAsyncResponse extends EInvoicingResponse Response to a request to the `sendAsync` method. This contains information about what has happened when executing `sendAsync`. This class extends c2g.SalesInvoiceEInvoicingService.EInvoicingResponse Properties
Methods
SendAsyncResponseglobal SendAsyncResponse(Id asyncApexJobId) Constructs a SendAsyncResponse. Input Parameters
SendAsyncResponseglobal SendAsyncResponse(Map<Id, List<String>> errorsById) Constructs a SendAsyncResponse. Input Parameters
c2g.SalesInvoiceEInvoicingService.PrepareToSendResponseglobal with sharing class PrepareToSendResponse extends EInvoicingResponse Response to a request to the `prepareToSend` method. This contains information about what has happened when executing `prepareToSend`. This response currently contains no information, and is present as a placeholder to allow us to add information to the response in future. This class extends c2g.SalesInvoiceEInvoicingService.EInvoicingResponse MethodsPrepareToSendResponseglobal PrepareToSendResponse() Constructs a PrepareToSendResponse with no errors set. PrepareToSendResponseglobal PrepareToSendResponse(Map<Id, List<String>> errorsByIds) Constructs a PrepareToSendResponse. Input Parameters
c2g.SalesInvoiceEInvoicingService.SendResponseglobal with sharing class SendResponse extends EInvoicingResponse Response to a request to the `sendPreparedInvoices` method. This contains information about what has happened when executing `sendPreparedInvoices`. This response currently contains no information, and is present as a placeholder to allow us to add information to the response in future. This class extends c2g.SalesInvoiceEInvoicingService.EInvoicingResponse MethodsSendResponseglobal SendResponse(Map<Id, List<String>> errorsById) Constructs a SendResponse. Input Parameters
c2g.SalesInvoiceEInvoicingService.ValidationResponseglobal with sharing class ValidationResponse extends EInvoicingResponse Returns information on the validity of sales invoices. This class extends c2g.SalesInvoiceEInvoicingService.EInvoicingResponse Properties
MethodsValidationResponseglobal ValidationResponse(Map<Id, List<String>> errorMap) ValidationResponseglobal ValidationResponse() |