# Generate checkout and preview links from Apex

### Overview

This feature enables **programmatic generation of Limio preview and checkout links** for Salesforce Quotes without rendering the Initiate Checkout Flow UI component.

The solution is **Flow-ready**, asynchronous, and provides a clear distinction between preview and checkout links so they can be routed to the correct Quote fields.

### Business Context & Motivation

A typical business use case requires:

* Preventing manual copying or pasting of checkout URLs
* Preventing direct navigation to the cart component
* Ensuring links are only exposed based on explicit business rules

Links must be generated and surfaced **automatically** when defined conditions are met, for example certain approvals, rather than through user interaction with the UI.

### Flow Configuration

#### Invocable Action

**Generate 2 Links for Limio Quote**

This invocable action asynchronously generates **preview and/or checkout links** for a Limio Quote, depending on the target fields provided.

#### Prerequisites

* One or two fields on the Limio Quote to store generated links

**Field requirements:**

* Field type must be **Text** or **URL**
* Field length must be sufficient to store a full URL

#### Link Generation Rules

Link generation behavior depends on which target fields are provided:

* If only the **preview target field** is provided → only a **preview link** is generated
* If only the **checkout target field** is provided → only a **checkout link** is generated
* If both target fields are provided → both **preview and checkout links** are generated
* Re-running the action overwrites any existing values in the target fields

#### Example Flow Setup

1. Create or edit a Salesforce Flow (record-triggered or autolaunched)
2. Add the **Generate 2 Links for Limio Quote** action
3. Provide values for the input properties lised below
4. Save and activate the Flow

<table data-header-hidden><thead><tr><th>Name</th><th>Notes</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>quoteId</td><td>Quote record ID</td><td>true</td></tr><tr><td>domain</td><td>htps://{yourShopDomain}.com</td><td>true</td></tr><tr><td>orderType</td><td>new</td><td>true</td></tr><tr><td>previewTargetFieldApiName</td><td>Preview_Link__c from previous step. <strong>At least one of the two must be present.</strong></td><td>false</td></tr><tr><td>checkoutTargetFieldApiName</td><td>Checkout_Link__c from previous step. <strong>At least one of the two must be present.</strong></td><td>false</td></tr><tr><td>previewPageTag</td><td>- tag of the page you want to navigate your user to</td><td>false</td></tr><tr><td>checkoutPageTag</td><td>- tag of the page you want to navigate your user to</td><td>false</td></tr><tr><td>customFieldsJson</td><td>JSON string which will be added to the order payload under order.customFields</td><td>false</td></tr><tr><td>customTrackingJson</td><td>JSON string which will extend order.tracking object</td><td>false</td></tr><tr><td>expiresAfter</td><td>specifies expiration time of the link<br>in format 'days/hours/minutes' ( ie '2/2/0' for 2 days and 2 hours, or '0/0/0' for expired). Can be assinged based on a parent Opportunity Close Date.</td><td>false</td></tr></tbody></table>

{% hint style="info" %}
The format for **customFieldsJson** is detailed in the following article: [Custom Fields](/integrations/using-limio-for-salesforce/passing-custom-fields.md)
{% endhint %}

#### Execution Result

The invocable action returns a result object indicating whether the request was successfully submitted for processing:

```
Result {
  success: Boolean
  errorMessage: String
}
```

{% hint style="info" %}
A successful response indicates that link generation was initiated. Actual link creation and field population occur **asynchronously**.
{% endhint %}

### Error Handling & Troubleshooting

#### Failure Behavior

If link generation fails, target fields remain unchanged and error details are logged in `ExceptionStorage__c`. Verify field configuration, Flow execution, and review logs for details.

#### Troubleshooting Checklist

1. Verify the target field API names are correct
2. Ensure target fields:
   * Are of type **Text** or **URL**
   * Are long enough to store full URLs
3. Review `ExceptionStorage__c` for error details
4. Confirm the Flow was triggered as expected


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.limio.com/integrations/using-limio-for-salesforce/using-quoting-tool/generate-checkout-and-preview-links-from-apex.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
