Short Answer
Every time an Opportunity is marked 'Closed-Won' in Salesforce, Zapier automatically syncs the customer data to Xero and generates a professional Draft Invoice with corresponding line items, ensuring financial accuracy and faster payments.
The Problem
Sales teams often experience a manual bottleneck when a deal is closed. Manually copying Salesforce Opportunity data into Xero for invoicing leads to data entry errors, delayed billing, and a lack of visibility for sales reps regarding payment status.
The Outcome
Every time an Opportunity is marked 'Closed-Won' in Salesforce, Zapier automatically syncs the customer data to Xero and generates a professional Draft Invoice with corresponding line items, ensuring financial accuracy and faster payments.
Step-by-Step Guide
1. **Authenticate Salesforce**: Create a new Zap and choose **Salesforce** as the Trigger. Select **Updated Field in Record**. Connect your Salesforce account and select 'Opportunity' as the Object and 'Stage' as the Field.
2. **Set Logic Filter**: Add a **Filter by Zapier** step. Configure it to only continue if the `Stage` field 'Exactly matches' `Closed-Won`. This prevents the Zap from consuming tasks on early-stage deals.
3. **Format Line Items**: If your Opportunity has multiple products, add **Formatter by Zapier > Utilities > Line Itemizer**. Map the Salesforce Opportunity Line Item Names, Quantities, and Prices. This ensures Xero receives an array rather than a single string.
4. **Sync Customer to Xero**: Add a **Xero** action step: **Find or Create Contact**. Search by the Salesforce 'Account Name'. Check the box 'Create Xero Contact if it doesn't exist yet' and map the Billing Address and Email from Salesforce.
5. **Generate Invoice**: Add a **Xero** action step: **Create Sales Invoice**.
- Select the Contact ID from the previous step.
- Set 'Status' to 'Draft' (safest for finance review).
- Map the Line Itemizer output to the 'Line Items' section.
- Map the Salesforce 'Opportunity ID' to the Xero 'Reference' field to prevent duplicates.
6. **Duplicate Prevention**: Before the Invoice step, you can optionally add a **Xero: Find Invoice** step using the Salesforce Opportunity ID. Use a Filter to only proceed if an invoice is *not* found.
7. **Close the Loop**: Add a final **Salesforce: Update Opportunity** action. Pass the 'Invoice ID' or 'Xero URL' back to a custom field in Salesforce so the Sales Rep can see the invoice was created.
8. **Turn on Error Handling**: Click the down arrow on the Xero step and select **'Add extra step' > 'Always hide/skip'** or use **Zapier Manager** to catch errors and send a Slack/Email alert if the invoice fails due to tax mapping issues.
Data Mapping
| Salesforce Field | Xero Field | Transformation / Logic | Required |
| :--- | :--- | :--- | :--- |
| Account Name | Contact Name | Map directly from Step 4 | Yes |
| Opportunity ID | Reference | Used for cross-referencing | Yes |
| Line Item: Total Price | Unit Amount | Ensure Currency matches in both apps | Yes |
| Line Item: Quantity | Quantity | Default to '1' if null | Yes |
| Account Billing Address | Postal Address | Use Formatter if Street/City are separate | No |
| Close Date | Date | Zapier converts SF ISO date to Xero format | Yes |
| Opportunity Name | Description | Used for Invoice Line Item text | No |
Gotchas & Failure Modes
* **Line Item Limits**: Standard Zapier Salesforce triggers may only pull the first line item. Use the 'Find Opportunity Line Items' Salesforce action if you need to fetch multiple products.
* **Tax Rates**: Xero requires specific Tax Types (e.g., 'OUTPUT'). If Salesforce doesn't store these, use a **Formatter Look-up Table** to convert Salesforce 'State' or 'Tax Category' into Xero's internal Tax Codes.
* **Task Usage**: Using 'Updated Field in Record' is more task-efficient than 'New Outbound Message' if you only want to track the Stage change.
* **Currency Mismatch**: Ensure the Currency Code in Salesforce (e.g., USD) matches a configured currency in Xero, or the API will return a 400 error.
Verification Checklist
- [ ] **Test Trigger**: Use a 'dummy' Opportunity in Salesforce and set it to 'Closed-Won'.
- [ ] **Check Formatter**: Confirm the Line Itemizer is correctly grouping multiple products into an array in the Zapier Task History.
- [ ] **Verify Contact**: Check Xero to ensure a new Contact wasn't created if one with the same name already existed (Duplication Check).
- [ ] **Review Draft**: Open the created Invoice in Xero and verify the 'Reference' field contains the Salesforce ID.
- [ ] **Monitor Task History**: Ensure no 'Stopped' status exists in Zapier due to mapping errors.
Ready to Automate?
Build this automation with Zapier in minutes.