---
title: Invoice Flow
slug: xero/invoice-flow
description: Learn how to use the Breadwinner Apex Generator to automate invoice record creation in Xero through Salesforce. This document provides step-by-step instructions on generating an Apex class, creating a record-triggered flow, retrieving line items and conta
docTags: 
createdAt: 2022-02-25T08:25:44.000Z
---

## 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&#x20;***&#x72;ecord 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.&#x20;

::embed[]{url="https://youtu.be/VdKHVzbHvXU"}

### 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:&#x20;**&#x53;elect the option for Run this Flow as (*I will check "Run Asynchronously" (on Record-Triggered flow creation Page)*)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/hbgCKWF7UsotI9jntpzAc_select-run-this-as.png)

**Step 3:** Click on Next, it will navigate to the ***Fields&#x20;***&#x73;election page. Click on ***Generate Apex***.

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/ANZddxKdxPUkl4T4um0IE_generate-apex.png)

**Step 4:&#x20;**&#x43;opy the generated ***Apex Class / Apex Test Class&#x20;**(optional). Save/Deploy&#x20;*&#x74;he copied code to the respective org.&#x20;

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/hakneQHddZEbOrwKXLjs3_copy-apex.png)

### Xero Invoice Automation using Flows

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

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/KSzr-utGhOXJFOstlcf8P_launch-record-trigger-flow.png)

**Step 2:&#x20;**&#x43;hoose the **options&#x20;**&#x73;imilar to those mentioned below, and click on ***Done***.

1. Select the Object (*Opportunity*)
2. Trigger Event (*record is updated*)
3. Entry Conditions (like *StgaeName&#x20;*&#x69;s *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*)&#x20;
6. Check Run Asynchronously path (Only when the option "*I will check "Run Asynchronously" (on Record-Triggered flow creation Page)" &#x20;*&#x6F;n Step 2)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/rYl08esiZUqdc4fVXpkZV_xero-invoice-creation-on-opportunity-with-breadwinner.png)

**Step 3:&#x20;**&#x47;et Line Items (***Opportunity Products*** query with Current Record ID (*opportunity Id*)), and click on ***Done***.

1. Select Get Records (from *Data&#x20;*&#x73;ection)
2. Select Object for Line Records (*Opportunity Product*)
3. Condition for Query (<font color="#2166ae">*OpportunityId* </font>*Equals&#x20;*<font color="#2166ae">*$Record &gt; Opportunity ID*</font>)
4. Sorting (*Ascending&#x20;*&#x62;y <font color="#2166ae">*#SortOrder*</font>)
5. How Many Record (*All Records*)
6. How to Store (*Automatically store all fields*)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/ub5sX118yfAipEkqr5D4K_xero-invoice-get-opportunity-products.png)

**Step 4:&#x20;**&#x47;et Xero **Contact Info** using *Get Records* data action, and click on **Done**.

1. Select Get Records (from *Data&#x20;*&#x73;ection)
2. Select Object for Info (Xer&#x6F;*&#x20;Contact*)
3. Condition for Query (*Breadwinner\_\_Salesforce\_Account\_\_c Equals&#x20;*<font color="#2166ae">*$Record &gt; Account ID &gt; Account ID*</font>)
4. Sorting (Optional)
5. How Many Record (Onl&#x79;*&#x20;first record*)
6. How to Store (*Choose fields and Salesforce do the rest* and select the below *fields&#x20;*&#x66;or further usage)
   - Breadwinner\_\_Xero\_Org\_ID\_\_c
   - Breadwinner\_\_Reference\_Id\_\_c

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/lPgRN1JerbU-fTFhcRwdc_xero-contact-info.png)

**Step 5:&#x20;**&#x43;reate an ***Apex Action*** using the "***Create Xero Invoice***" Invocable method

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/MHwBLrkEliscqk060Q9aI_xero-invocable-action.png)

**Step 6:&#x20;**&#x4D;ap the **Fields&#x20;**&#x74;o Create Invoice in "***Apex Action***"

1. Select Object for "Invoice Line Items" input (*Opportunity Product*)
2. Map the input with Record fields (*Eg:&#x20;*<font color="#2166ae">*\{!$Record.CreatedDate\}*</font>)
3. Map the Line Records to "Invoice Line Items" (Created from Step 3, Eg: <font color="#2166ae">*\{!Get\_Opportunity\_Products\}*</font>)
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: <font color="#2166ae">*\{!Get\_Xero\_Contact\_Information.Breadwinner\_\_Salesforce\_Account\_\_c\}*</font>)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/z9WvJDyIBL_imRa0MUCRj_apex-action-mappings.png "Fields Mapping")

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/UfpbBOiy_GDF64Y_A1ZfZ_line-api-names.png "Line API Na")

**Step 7:&#x20;**&#x20;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&#x20;***&#x74;o ***Get Xero Contact Information&#x20;***
3. Connect ***Get Contact Information&#x20;***&#x74;o ***Create Xero Invoice on Opportunity&#x20;***

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/sKGKO5RQMaiDBgi_1UbsP_flow-steps-linking.png)

### Triggering Xero Invoice creation

**Step 1:** Select the Opportunity

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/jg0AmLaBAPl0dkEsRGPjn_coles-supermarkets-salesforce.png)

**Step 2:** Edit the Opportunity to meet **Trigger&#x20;**&#x43;riteria (***StageName > Closed Won***)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/h1S_r2gePTyGUGncfIgFr_edit-coles-supermarkets-salesforce.png)

**Step 3:** Evaluate the created ***Invoice&#x20;***&#x61;t Xero

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/1Sm36ZP_-_cQxG_qsGDRb_invoice-xero.png)

If all the details are mapped as expected, your ***Xero Invoice Automation*** with Breadwinner was ***Successful***.&#x20;











