---
schema_version: "1"
id: f3efa791b499f59757b62de018795c5057e80cf10315db56f740d7460f905178
title: Ensure Refunds Async Action
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/flow_ref_elements_om_actions_ensure_refunds_async.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_om_actions_ensure_refunds_async.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 590869910420e5f169d275ddc2f32c0e6dafdea080dbbdc604a3ef6746bb7647
description: In Salesforce Order Management, ensure refunds for a credit memo or excess funds by sending a request to a payment provider. This action inserts a background operation into an asynchronous job queue and returns the ID of that operation so you can track its status. Payment gateway responses appear in the payment gateway log and don’t affect the background operation status.
products:
  - Flow Builder
  - Salesforce Platform
release: "264"
---
# Ensure Refunds Async Action

In Salesforce Order Management, ensure refunds for a credit memo or excess funds by sending a request to a payment provider. This action inserts a background operation into an asynchronous job queue and returns the ID of that operation so you can track its status. Payment gateway responses appear in the payment gateway log and don’t affect the background operation status.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=platform.flow_ref_supported_editions.htm&amp;release=264.0.0&amp;type=5" title="Learn about the editions and user interfaces that support Flow Builder. Some Flow Builder features integrate with other Salesforce products that require additional licenses.">View supported editions.</a></td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">This feature requires the Salesforce Order Management add-on. To purchase, contact your Salesforce account executive.</td></tr></tbody></table>

In Flow Builder, add an Action element to your flow. Select the **Order Management** category, and search for **Ensure Refunds Async**.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-platform_automation-264-0-0-production-enus/60568438-ec7e-4665-acd1-7c80dcbe60d5/images/icon_note.png)

Note If the action creates a refund, the refund record’s ClientContext value isn’t predictable. Don't use it in custom logic.

Set Input Values

Use values from earlier in the flow to set the inputs.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:17.006802721088434%">
          <col style="width:82.99319727891157%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d269992e85">Input Parameter</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d269992e88">Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Input Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d269992e85 "><strong class="uicontrol">Ensure Refunds Async Input</strong></td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d269992e88 ">
              <p>This input is an Apex-defined variable of class <a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_input_ensure_refunds_async.htm" target="_blank">ConnectApi.EnsureReundsAsyncInputRepresentation</a>.</p>
              <p>The variable has these
                fields. You can specify either <strong class="uicontrol">creditMemoId</strong> or
                <strong class="uicontrol">excessFundsAmount</strong>, or you can specify both. If you're
                requesting a refund for a cancelled item, but an invoice was already generated and
                sent to <strong class="uicontrol">ensureFunds</strong>, specify
                <strong class="uicontrol">creditMemoId</strong>.
              </p>
              <ul>
                <li><strong class="uicontrol">creditMemoId</strong>—The ID of the credit memo to ensure
                  refunds for.</li>

                <li><strong class="uicontrol">excessFundsAmount</strong>—The amount of excess funds to apply
                  the refunds against.</li>

                <li><strong class="uicontrol">invoicesToPay</strong>—List of invoices for fees that reduce the
                  refund, such as return fees.</li>

                <li><strong class="uicontrol">isAllowPartial</strong>—This value controls the behavior when
                  the amounts included in the <strong class="uicontrol">sequences</strong> list don’t cover
                  the entire refund amount. If this value is false, the default refund logic is
                  applied to ensure the remaining refund amount. If this value is true, the
                  unrefunded balance remains on the credit memo. If you don’t specify a
                  <strong class="uicontrol">sequences</strong> list, this value is ignored, and the default
                  refund logic is applied. The default is false.
                </li>

                <li><strong class="uicontrol">sequences</strong>—This input is an ordered list of refund
                  amounts and the OrderPaymentSummaries to apply them to. The process traverses
                  this list in order and stops when it has refunded the full amount. It’s a list
                  of Apex-defined variables of class
                  SequenceOrderPaymentSummaryInputRepresentation. It contains these fields:<ul>
                    <li><strong class="uicontrol">amount</strong>—Amount of the refund to apply to the
                      OrderPaymentSummary.</li>

                    <li><strong class="uicontrol">orderPaymentSummaryId</strong>—ID of the OrderPaymentSummary
                      to apply the Amount to.</li>

                  </ul>
                </li>

              </ul>
            </td>

          </tr>
          <tr class="">
            <td data-label="Input Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d269992e85 "><strong class="uicontrol">Order Summary Id</strong></td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d269992e88 ">Reference to the order summary associated with the credit memo.</td>

          </tr>
        </tbody>
      </table>

Store Output Values

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:17.513134851138354%">
          <col style="width:82.48686514886164%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d269992e194">Output Parameter</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d269992e197">Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Output Parameter" class="slds-cell-wrap" style="vertical-align:top;" headers="d269992e194 "><strong class="uicontrol">Ensure Refunds Async Output</strong></td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d269992e197 ">
              <p>This value is an Apex-defined variable of class <a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_output_ensure_refunds_async_output.htm" target="_blank">EnsureRefundsAsyncOutputRepresentation</a>. It
                only returns the ID of the asynchronous background operation, regardless of whether
                a call is made to an external payment gateway. It doesn’t include any errors from
                the operation.</p>
              <p style="margin-bottom:0;">The <strong class="uicontrol">backgroundOperationId</strong> field contains the
                ID of the background operation.</p>
            </td>

          </tr>
        </tbody>
      </table>

Usage

This action applies the refund to order payment summaries associated with the specified order summary following this logic.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-platform_automation-264-0-0-production-enus/60568438-ec7e-4665-acd1-7c80dcbe60d5/images/icon_note.png)

Note If multiple order payment summaries have equal **AvailableToRefund** amounts, their order of selection is random.

- Verify that the credit memo balance and excess funds amount don't exceed the total **AvailableToRefund** amount of all the order payment summaries associated with the order summary.
- If **sequences** is specified, follow these steps.
    - Traverse the **sequences** list in order and apply the specified refund amounts to the specified order payment summaries.
    - If the specified credit memo and excess funds are fully refunded, or if **isAllowPartial** is true, then the action stops here.
- If a credit memo is specified, follow these steps.
    - If an order payment summary has an **AvailableToRefund** amount matching the credit memo’s remaining balance, apply the refund to that payment.
    - If no exact match was found, apply the refund to the order payment summary with the largest **AvailableToRefund** amount.
    - If the credit memo has any remaining balance, repeat steps a and b until that balance is fully refunded.
- If only one OrderPaymentSummary is specified but has multiple payments, follow these steps.
    - If a payment has an amount matching the CreditMemo’s remaining balance, apply the refund to that payment.
    - If no exact match was found but one or more payment has a large enough amount to cover the balance, use the payment with the smallest amount.
    - If no single payment has a large enough amount, use multiple payments in descending order of amount. This ensures the fewest payments are used.
- If an excess funds amount is specified, follow these steps.
    - Examine those order payment summaries. If one has an **AvailableToRefund** amount matching the excess funds amount, apply the refund to that payment.
    - If no exact match was found, apply the refund to the order payment summary with the largest **AvailableToRefund** amount.
    - If any excess funds amount remains, repeat steps a and b until it’s fully refunded.

#### See Also

- [Create Credit Memo Action](https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_om_actions_create_credit_memo.htm&release=264.0.0&type=5 "In Salesforce Order Management, create a credit memo to represent the refund for one or more change orders associated with an order summary.")
- [Create an Invoice from Change Orders Action](https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_om_actions_create_invoice_from_change_orders.htm&release=264.0.0&type=5 "In Salesforce Order Management, create an invoice to represent the charges for one or more change orders. Create invoices for change orders that increase order amounts, such as return fees. When you ensure the refund for a return, include the invoices for the associated return fees in the input.")
- [Return Order Items Action](https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_om_actions_return_return_order_items.htm&release=264.0.0&type=5 "In Salesforce Order Management, process one or more return order line items belonging to a return order. This action creates a change order record for the returned items and makes the processed return order line items read-only. You can include return order fees associated with the return order line items. If you do, a change order record is created for the return fees. If a processed return order line item has a remaining expected quantity, the action creates a separate return order line item representing that quantity.")
- [Ensure Funds Async Action](https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_om_actions_ensure_funds_async.htm&release=264.0.0&type=5 "Ensure funds for an invoice, and apply them to the invoice. Optionally, apply the funds in a defined sequence. If needed, capture authorized funds by sending a request to a payment provider. This action inserts a background operation into an asynchronous job queue and returns the ID of that operation so you can track its status. Payment gateway responses appear in the payment gateway log and don’t affect the background operation status.")
- [Add and Edit Elements](https://help.salesforce.com/s/articleView?id=platform.flow_build_elements.htm&release=264.0.0&type=5 "Use elements to define actions that the flow can run. When they’re on the canvas, connect them to create the order in which they run.")