Select Page

Salesforce to Xero Integration via Apex

Overview of Integration

Integration of Xero (used for accounting) and Salesforce CRM is required to automate several tasks. Simplification of creating and viewing Xero Customers and Invoices can be achieved by integrating the aforementioned apps. Even if the pre-built Salesforce Integration for Xero may not suffice for your company’s needs, a custom Apex can be created and a solution developed. Instruction on achieving this will be provided in this post! Combining the two platforms requires admin access to Salesforce (Enterprise Edition or higher, or a Dev/Sandbox org for testing) and Xero. Additionally, prior knowledge of Apex coding is necessary. If Apex utilization is unfamiliar, consideration might be given to employing Zapier’s no-code integration or Breadwinner’s no-code interface with Salesforce.

Remote Site Settings

Registering the target site in the Remote Site Settings is necessary for a callout from Salesforce to an external website. Salesforce restricts calls to unregistered network addresses. If the site is not registered, the callout will not function. Before calling Xero Endpoints, two remote site configurations must be created in Salesforce using below mentioned steps:

  1. Go to Setup.
  2. Type “Remote Site” into the Quick Find search bar.
  3. Then select “Remote Site Settings.”
  4. Make the following two remote site configurations, each with a distinct function.
    1. Use this URL to authenticate yourself and get the access token: https://identity.xero.com/
    2. Use this URL to carry out operations on data, including contacts, invoices, bills, and purchase orders:

Xero Contacts

Reading Contacts

To get the details of your Xero Contact(s), use the code below. You may also use the “IDs” option in the endpoint to retrieve specific Xero Contact information.

By providing the “IDs” option along with the code, you can obtain specific Xero contacts, as demonstrated by the URL below.
https://api.xero.com/api.xro/2.0/Contacts?IDs=220ddca8-3144-4085-9a88-2d72c5133734,88192a99-cbc5-4a66-bf1a-2f9fea2d36d0

Managing Xero Contacts – Creation and Update

Adhering to Xero API guidelines necessitates completing certain mandatory fields when creating a Xero Contact. Moreover, when upgrading a Xero Contact, it’s crucial to incorporate the “ContactID” in the request body. The provided code can be employed to create or update a Xero contact based on the value of the “isCreate” option. If the “isCreate” argument is TRUE, the request method will be specified as PUT; otherwise, it will be configured as POST.

Xero Invoices

Reading Invoices

To get the details of a Xero invoice(s) from Xero, use the code that is provided below. You may also use the “IDs” option in the endpoint to retrieve specific Xero Invoice data.

With the given code and the “IDs” option, you can obtain specific Xero invoices, as the following API illustrates.
https://api.xero.com/api.xro/2.0/Invoices?IDs=fee88eea-f2aa-4a71-a372-33d6d83d3c45,9f5bca33-8590-4b6f-acfb-e85712b10217

Managing Xero Invoices – Creation and Update

In accordance with Xero API guidelines, a few required fields must be filled out when generating a Xero invoice. However, it is essential to include the “InvoiceID” in the request body when changing a Xero invoice. Depending on the value of the “isCreate” option, the code below can be used to create or update a Xero invoice. The request method will be specified as PUT if the “isCreate” argument is set to TRUE; otherwise, it will be configured as POST.

 

Alternatives to a Custom Integration

Breadwinner’s Xero Salesforce Integration is an alternative option, if there are challenges in developing a customized Apex integration. It may be due to limitations such as the absence of LWC components or difficulties in managing updates and race conditions. This solution can aid in the rapid expansion and scaling of your organization, with clear and defined costs. Alternatively, integration of Salesforce and Xero can be achieved using Workato or Zapier.

Recommended Blog