fferpcore.BillingDocumentServiceglobal with sharing class BillingDocumentService
Services for Billing Documents. Properties
EnumsTypeAn enum that represents the valid options for the billing document type.
ProcessStateState of a completion process.
Methods
completeDocumentsglobal static Map<Id, fferpcore.BillingDocumentService.ProcessResult> completeDocuments(Set<Id> billingDocumentIds) Complete billing documents. The documents must be in draft state, have a least one line and not have a completion in progress. Applications may add further validation. Input Parameters
Return ValueMap of completion process results keyed on billing document Id. verifyPermissionsForCalculateTaxglobal static fferpcore.BillingDocumentService.CalculateTaxPermissionResponse verifyPermissionsForCalculateTax() Verifies that the current user has sufficient permissions to calculate tax. The same check is used by calculateTax. We recommend that you call this before attempting to call calculateTax. For example, if you have a screen which calculates tax, you can call verifyPermissionsForCalculateTax when the user arrives on the screen to check that they have the correct permissions to use it. Return ValueThe results of the verification. See BillingDocumentService.CalculateTaxPermissionResponse for details. verifyAsyncPermissionsForCalculateTaxglobal static fferpcore.BillingDocumentService.CalculateTaxAsyncPermissionResponse verifyAsyncPermissionsForCalculateTax() Verifies that the current user has sufficient permissions to calculate tax asynchronously. The same check is used by calculateTaxAsync. We recommend that you call this before attempting to call calculateTaxAsync. For example, if you have a screen which calculates tax asynchronously, you can call verifyAsyncPermissionsForCalculateTax when the user arrives on the screen to check that they have the correct permissions to use it. Return ValueThe results of the verification. See BillingDocumentService.CalculateTaxAsyncPermissionResponse for details. validateForCalculateTaxglobal static fferpcore.BillingDocumentService.CalculateTaxValidationResponse validateForCalculateTax(fferpcore.BillingDocumentService.CalculateTaxValidationDocument request) Verifies that a billing document is valid for calculating tax. The same check is used by calculateTax and calculateTaxAsync. If the check fails then the calculate process does not work. We recommend that you call this before attempting to calculate tax. For example, if you have a process which attempts to calculate tax automatically, you can use validateForCalculateTax to filter out invalid documents upfront. Input Parameters
Exceptions Thrown
Return ValueThe results of the validation. See BillingDocumentService.CalculateTaxValidationResponse for details. calculateTaxglobal static fferpcore.BillingDocumentService.CalculateTaxResponse calculateTax(fferpcore.BillingDocumentService.CalculateTaxRequest request) Calculates tax on selected billing documents. Existing tax codes, rates, and values for the billing document line items are cleared and then populated with the calculated values. Input Parameters
Exceptions Thrown
Return ValueThe results of calculating tax, showing which billing documents have been successful. 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. /** * This example shows a simple controller class which allows a user to calculate tax for several billing documents selected from a list view. * It checks first whether a user has access to the required objects. If they do not then it shows any errors and does not proceed. * When the user tries to calculate tax it checks whether any documents are invalid, and removes them from the request. All valid documents * are sent to have tax calculated. Any errors encountered are shown on the screen. * Note that this is only appropriate for dealing with a small number of billing documents which do not have many lines, because all the documents will * be updated in a single transaction and so may run into Salesforce platform limits on the amount of work that can be performed. For larger * documents calculateTaxAsync is appropriate instead, and the permission check would be replaced with a call to verifyAsyncPermissionsForCalculateTax. */ public class CalculateTaxController { private List<fferpcore__BillingDocument__c> billingDocuments; private Boolean hasPermission; public CalculateTaxController(ApexPages.StandardSetController stdController) { //The selected billing documents billingDocuments = (List<fferpcore__BillingDocument__c>)stdController.getSelected(); //Checks that the running user has the permissions necessary to calculate tax fferpcore.BillingDocumentService.CalculateTaxPermissionResponse permission = fferpcore.BillingDocumentService.verifyPermissionsForCalculateTax(); if (permission.Errors.isEmpty()) { hasPermission = true; } else { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, permission.Errors[0])); hasPermission = false; } } public void calculateTax() { if (!hasPermission) { return; } fferpcore.BillingDocumentService.CalculateTaxRequest calculateRequest = new fferpcore.BillingDocumentService.CalculateTaxRequest(); //Finds which documents are valid upfront, and only tries to calculate tax for the valid ones for (fferpcore__BillingDocument__c document : billingDocuments) { fferpcore.BillingDocumentService.CalculateTaxValidationDocument validationRequest = new fferpcore.BillingDocumentService.CalculateTaxValidationDocument(); validationRequest.AccountId = document.fferpcore__Account__c; validationRequest.CompanyId = document.fferpcore__Company__c; validationRequest.CompanyTaxInformationId = document.fferpcore__Company__r.fferpcore__TaxInformation__c; validationRequest.DocumentDate = document.fferpcore__DocumentDate__c; validationRequest.Status = document.fferpcore__DocumentStatus__c; fferpcore.BillingDocumentService.CalculateTaxValidationResponse validateResponse = fferpcore.BillingDocumentService.validateForCalculateTax(validationRequest); if (validateResponse.Errors.isEmpty()) { //Success! We know this document will be valid for tax calculation. calculateRequest.BillingDocumentIds.add(document.Id); } else { //Shows the problems we encountered for particular documents. for (String error : validateResponse.Errors) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error for document ' + document.Id + ': ' + error)); } } } //Calculates tax and updates the documents fferpcore.BillingDocumentService.CalculateTaxResponse calculateResponse = fferpcore.BillingDocumentService.calculateTax(calculateRequest); //Certain errors, such as an invalid set of tax rates, will only surface after calculating tax, so it's important to check whether this has been successful. for (fferpcore.BillingDocumentService.CalculateTaxResult result : calculateResponse.Results) { if (result.Errors.isEmpty()) { //Tax calculated successfully! ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Tax calculated for ' + result.DocumentId)); } else { for (String error : result.Errors) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error for document ' + result.DocumentId + ': ' + error)); } } } } } calculateTaxAsyncglobal static fferpcore.BillingDocumentService.CalculateTaxAsyncResponse calculateTaxAsync(fferpcore.BillingDocumentService.CalculateTaxAsyncRequest request) Calculates tax on billing documents by running an asynchronous process. Existing tax codes, rates, and values for the billing document line items are cleared and then populated with the calculated values. Input Parameters
Exceptions Thrown
Return ValueThe results of the asynchronous process creation. Results for calculating tax are not returned in this response, but are created as fferpcore__ScheduledJobLog__c records against the fferpcore__ScheduledJobRun__c record created here. getTaxglobal static fferpcore.BillingDocumentService.GetTaxResponse getTax(fferpcore.BillingDocumentService.GetTaxRequest request) Calculates tax for the documents provided and returns the calculated tax data. You can use this service for calculating tax on unsaved documents before saving them. The documents provided represent the data that is available on a billing document, but they do not relate to a record on the database. This service does not perform DML. Input Parameters
Exceptions Thrown
Return ValueResults of calculating tax for each document. deriveDueDateglobal static List<fferpcore.BillingDocumentService.DeriveDueDateResponse> deriveDueDate(List<fferpcore.BillingDocumentService.DeriveDueDateRequest> requests) Derives the document due date for a list of billing documents. Input Parameters
Return ValueThe result of deriving the document due date for a list of billing documents. The list of responses is returned in the same order as the list of requests. fferpcore.BillingDocumentService.ProcessResultglobal inherited sharing class ProcessResult The result of a completion process. Properties
MethodsProcessResultglobal ProcessResult(Id documentId, fferpcore.BillingDocumentService.ProcessState state, List<String> messages) Constructs a ProcessResult. Input Parameters
fferpcore.BillingDocumentService.AbstractCalculateTaxPermissionResponseglobal inherited sharing abstract class AbstractCalculateTaxPermissionResponse Abstract base class for responses containing the results of checking permission to calculate tax. Properties
fferpcore.BillingDocumentService.CalculateTaxPermissionResponseglobal inherited sharing class CalculateTaxPermissionResponse extends AbstractCalculateTaxPermissionResponse Response containing the results of checking permission to calculate tax. This class extends fferpcore.BillingDocumentService.AbstractCalculateTaxPermissionResponse fferpcore.BillingDocumentService.CalculateTaxAsyncPermissionResponseglobal inherited sharing class CalculateTaxAsyncPermissionResponse extends AbstractCalculateTaxPermissionResponse Response containing the results of checking permission to calculate tax asynchronously. This class extends fferpcore.BillingDocumentService.AbstractCalculateTaxPermissionResponse fferpcore.BillingDocumentService.CalculateTaxValidationDocumentglobal inherited sharing class CalculateTaxValidationDocument Represents a billing document to be validated for calculating tax. You should set all fields from the document to be validated. This is used by BillingDocumentsService.validateForCalculateTax to validate a document for tax calculation. Properties
MethodsCalculateTaxValidationDocumentglobal CalculateTaxValidationDocument() Constructs a new empty document. fferpcore.BillingDocumentService.CalculateTaxValidationResponseglobal inherited sharing class CalculateTaxValidationResponse Response containing the results of validation performed on a billing document for calculating tax. If there are no errors then the document can have tax calculated for it. Properties
fferpcore.BillingDocumentService.AbstractCalculateTaxRequestglobal inherited sharing abstract class AbstractCalculateTaxRequest Abstract base class for requests to calculate tax. Properties
fferpcore.BillingDocumentService.CalculateTaxRequestglobal inherited sharing class CalculateTaxRequest extends AbstractCalculateTaxRequest A request to calculate tax synchronously for selected billing documents. This class extends fferpcore.BillingDocumentService.AbstractCalculateTaxRequest MethodsCalculateTaxRequestglobal CalculateTaxRequest() Constructs a new empty request and sets BillingDocumentIds to be a new Set<Id>. fferpcore.BillingDocumentService.CalculateTaxResponseglobal inherited sharing class CalculateTaxResponse The results of calculating tax. There is one result for each document processed, successful or not. Properties
fferpcore.BillingDocumentService.CalculateTaxResultglobal inherited sharing class CalculateTaxResult The results of calculating tax on a single billing document. A billing document was processed successfully if no errors occur. Properties
fferpcore.BillingDocumentService.GetTaxRequestglobal inherited sharing class GetTaxRequest Contains the parameters required for calculating tax on multiple unsaved documents. Properties
MethodsGetTaxRequestglobal GetTaxRequest() Constructs a new empty request and sets Documents to be a new List<TaxDocument>. fferpcore.BillingDocumentService.TaxDocumentglobal inherited sharing class TaxDocument An unsaved document for which you can calculate tax. Properties
MethodsTaxDocumentglobal TaxDocument() Constructs a new empty document and sets Lines to be a new List<TaxDocumentLine>. fferpcore.BillingDocumentService.TaxAccountglobal inherited sharing class TaxAccount An account that can be charged or credited by a TaxDocument. Used for determining the tax to be applied to the document. You should set all fields from the account for the document to have tax calculated. Properties
Methodsfferpcore.BillingDocumentService.TaxCompanyglobal inherited sharing class TaxCompany A company which owns TaxDocuments. Used for determining the tax to be applied to the document. You should set all fields from the company for the document to have tax calculated. Properties
Methodsfferpcore.BillingDocumentService.TaxDocumentLineglobal inherited sharing class TaxDocumentLine A line on a document for which tax can be calculated. Properties
Methodsfferpcore.BillingDocumentService.TaxProductglobal inherited sharing class TaxProduct A product on a document line for which tax can be calculated. You should set all fields from the product for the billing document line to have tax calculated. Properties
Methodsfferpcore.BillingDocumentService.GetTaxResponseglobal inherited sharing class GetTaxResponse The results of calculating tax on unsaved documents. Properties
fferpcore.BillingDocumentService.GetTaxResultglobal inherited sharing class GetTaxResult A result from the tax calculation process for an unsaved document. This contains either the taxed lines or the errors encountered calculating tax for this document. The tax calculation was successful only if there are no errors. Properties
fferpcore.BillingDocumentService.GetTaxLineResultglobal inherited sharing class GetTaxLineResult Contains the calculated tax codes, rates, and values for a document line. Some values may be null depending on the configuration of your tax request. Properties
fferpcore.BillingDocumentService.CalculateTaxAsyncRequestglobal inherited sharing class CalculateTaxAsyncRequest extends AbstractCalculateTaxRequest A request to calculate tax asynchronously for selected billing documents. This class extends fferpcore.BillingDocumentService.AbstractCalculateTaxRequest MethodsCalculateTaxAsyncRequestglobal CalculateTaxAsyncRequest() Constructs a new empty request and sets BillingDocumentIds to be a new Set<Id>. fferpcore.BillingDocumentService.CalculateTaxAsyncResponseglobal inherited sharing class CalculateTaxAsyncResponse The results of creating an asynchronous tax calculation job. Properties
fferpcore.BillingDocumentService.DeriveDueDateRequestglobal inherited sharing class DeriveDueDateRequest A request to derive the document due date of a billing document. Properties
MethodsDeriveDueDateRequestglobal DeriveDueDateRequest() fferpcore.BillingDocumentService.DeriveDueDateResponseglobal inherited sharing class DeriveDueDateResponse The result of deriving the due date of a billing document. Properties
MethodsDeriveDueDateResponseglobal DeriveDueDateResponse() |