How to alter the AvaTax for Salesforce connector?
Overview
I would like to modify my AvaTax for Salesforce connector.
Environment
Salesforce
Resolution
-
Salesforce is a very flexible program and the out-of-the-box integration uses very specific fields to pull and push information to and from.
-
To alter any of these data sources, you will need to extend the classes.
-
This means you may use custom buttons for calculating tax, and not the ones we install.
-
-
- What you can do is extend any TaxNow, AvaTaxSDK or even AVA_SFQuotes package via polymorphism (derived from Apex class inheritance model).
- As an example, below is code that extends the AVA_SFCORE.GetTaxOpportunity class to override the address object used in an opportunity (Destination vs. billing address essentially).
- Most extensions of this type will follow a similar syntax.
- You may also want to create buttons to go with your extension.
public with sharing class CustomOppGetTax { extends AVA_SFCORE.GetTaxOpportunity { private List<Opportunity> clopps;
// query for the additional custom fields to be used in FetchDestinationAddress and FetchTaxData public CustomOppGetTax(ApexPages.StandardController controller) { clopps = [select Id, Ship_to_Address__c, Ship_to_Address_2__c, Ship_to_City__c, Ship_to_State__c, Ship_to_Zip__c, Ship_to_Country__c, Service_Address1__c, Service_Address2__c, Service_City__c, Service_State__c, Service_Zip__c, Sales_Tax_Exempt__c, Oppty_Specific_EBS__c from Opportunity where Id=:loOpp[0].Id]; }
// Override FetchDestination Address to fetch from custom fields public override AVA_SF_SDK.TaxSvc.BaseAddress FetchDestinationAddress() { AVA_SF_SDK.TaxSvc.BaseAddress oDestinationAddress = new AVA_SF_SDK.TaxSvc.BaseAddress(); oDestinationAddress.AddressCode = 'D'; if(loCfg[0].AVA_SFCORE__Use_BillingAddress__c == true) { // use service address oDestinationAddress.Line1 = clopps[0].Service_Address1__c; oDestinationAddress.Line2 = clopps[0].Service_Address2__c; oDestinationAddress.City = clopps[0].Service_City__c; oDestinationAddress.Region = clopps[0].Service_State__c; oDestinationAddress.PostalCode = clopps[0].Service_Zip__c; } else { // use ship_to address oDestinationAddress.Line1 = clopps[0].Ship_to_Address__c; oDestinationAddress.Line2 = clopps[0].Ship_to_Address_2__c; oDestinationAddress.City = clopps[0].Ship_to_City__c; oDestinationAddress.Region = clopps[0].Ship_to_State__c; oDestinationAddress.PostalCode = clopps[0].Ship_to_Zip__c; oDestinationAddress.Country = clopps[0].Ship_to_Country__c; }
return oDestinationAddress; }
// Override FetchTaxData to account for Exempt flag and Company Code public override AVA_SF_SDK.TaxSvc.GetTaxRequest FetchTaxData(Boolean commitFlag) { AVA_SF_SDK.TaxSvc.GetTaxRequest rVal = super.FetchTaxData(commitFlag); if(clopps[0].Sales_Tax_Exempt__c == 'Yes') { rVal.ExemptionNo = 'Exempt'; } else { rVal.ExemptionNo = ''; } rVal.CompanyCode = clopps[0].Oppty_Specific_EBS__c;
return rVal; } } |