Global API
Code Examples

Invoice Flow

10min

Custom Apex Generator

This is an example Invocable Method generated by Breadwinner Apex Generator, which can be invoked by a standard Flow. This is useful as it shows how you can use Salesforce standard automation practices to drive Xero record creation. Using this format, you can extend to Update or Read in a similar fashion.

This basic use case shows how easy it is to create robust automation in Salesforce to facilitate Invoice record creation in Xero. Extending upon this, using the Global API requests in this help site you can perform many automated retrieves, create, or update functions directly rather than requiring extensive middleware or endpoint processing to perform.







Apex Class Generation

Navigate to Breadwinner Setup > Tools > Apex Generator

Step 1: Choose the record mode Create/Edit on a Xero object (Invoice) using a Flow

Step 2: Select the option for Run this Flow as (I will check "Run Asynchronously" (on Record-Triggered flow creation Page))

Document image


Step 3: Click on Next, it will navigate to the Fields selection page. Click on Generate Apex.

Document image


Step 4: Copy the generated Apex Class / Apex Test Class (optional). Save/Deploy the copied code to the respective org.

Document image


Xero Invoice Automation using Flows

Step 1: Navigate to Salesforce Setup > Flows > New Flow > Record-Triggered Flow

Document image


Step 2: Choose the options similar to those mentioned below, and click on Done.

  1. Select the Object (Opportunity)
  2. Trigger Event (record is updated)
  3. Entry Conditions (like StgaeName is Closed Won)
  4. Run the Flow for updated records (Only when record is updated to meet the condition requirements)
  5. Optimize Flow for (Actions and Related Records)
  6. Check Run Asynchronously path (Only when the option "I will check "Run Asynchronously" (on Record-Triggered flow creation Page)" on Step 2)
Document image


Step 3: Get Line Items (Opportunity Products query with Current Record ID (opportunity Id)), and click on Done.

  1. Select Get Records (from Data section)
  2. Select Object for Line Records (Opportunity Product)
  3. Condition for Query (OpportunityId Equals $Record > Opportunity ID)
  4. Sorting (Ascending by #SortOrder)
  5. How Many Record (All Records)
  6. How to Store (Automatically store all fields)
Document image


Step 4: Get Xero Contact Info using Get Records data action, and click on Done.

  1. Select Get Records (from Data section)
  2. Select Object for Info (Xero Contact)
  3. Condition for Query (Breadwinner__Salesforce_Account__c Equals $Record > Account ID > Account ID)
  4. Sorting (Optional)
  5. How Many Record (Only first record)
  6. How to Store (Choose fields and Salesforce do the rest and select the below fields for further usage)
    • Breadwinner__Xero_Org_ID__c
    • Breadwinner__Reference_Id__c
Document image


Step 5: Create an Apex Action using the "Create Xero Invoice" Invocable method

Document image




Step 6: Map the Fields to Create Invoice in "Apex Action"

  1. Select Object for "Invoice Line Items" input (Opportunity Product)
  2. Map the input with Record fields (Eg: {!$Record.CreatedDate})
  3. Map the Line Records to "Invoice Line Items" (Created from Step 3, Eg: {!Get_Opportunity_Products})
  4. Map the Line Record fields with API Names (Field Name, Eg: Description) by coping as mentioned in the below image (Line API Names (2nd image))
  5. Map the Xero Contact Info (Created from Step 4, Eg: {!Get_Xero_Contact_Information.Breadwinner__Salesforce_Account__c})
Fields Mapping
Fields Mapping




Line API Na
Line API Na




Step 7: Connect the Flow Steps, Click Save, and Activate

  1. Connect Record Trigger Flow Section to Get Opportunity Products (Run Asynchronously)
  2. Connect Get Opportunity Products to Get Xero Contact Information
  3. Connect Get Contact Information to Create Xero Invoice on Opportunity
Document image




Triggering Xero Invoice creation

Step 1: Select the Opportunity

Document image




Step 2: Edit the Opportunity to meet Trigger Criteria (StageName > Closed Won)

Document image




Step 3: Evaluate the created Invoice at Xero

Document image


If all the details are mapped as expected, your Xero Invoice Automation with Breadwinner was Successful.