> For the complete documentation index, see [llms.txt](https://docs.limio.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.limio.com/salesforce/cpq/generate-links-from-apex.md).

# Links from Apex

### Overview

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

The action is **Flow-ready**. By default, it runs asynchronously. It keeps preview links and checkout links apart, so that you can save each link in the correct field of the quote.

### 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 generates **preview and/or checkout links** for a Limio Quote, depending on the target fields provided. By default it runs asynchronously. Set **generateAsync** to false to wait for the result.

The action is available from v13.71. **generateAsync** is available from v13.80, update links from v14.03, and **updateTag** from v14.24.

#### Prerequisites

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

**Field requirements:**

* Field type must be **Text**, **Long Text Area** or **URL**. The package includes the fields `i42as__Preview_Link__c` and `i42as__Checkout_Link__c`.
* 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
* For a quote with a **Subscription Id**, the action generates one update link, `<domain>/<updateTag>?basket=<basket id>`. It writes this link to each target field that you provide
* From v14.41, the action also writes the id of the Limio basket to **Limio Basket Id** on the quote. When it generates both links, it writes the basket of the checkout link

#### 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 listed 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>https://{yourShopDomain}.com</td><td>true</td></tr><tr><td>orderType</td><td>new. For a quote with a <strong>Subscription Id</strong>, the action ignores this value.</td><td>true</td></tr><tr><td>previewTargetFieldApiName</td><td>The API name of the field for the preview link, for example <code>i42as__Preview_Link__c</code>. <strong>At least one of the two must be present.</strong></td><td>false</td></tr><tr><td>checkoutTargetFieldApiName</td><td>The API name of the field for the checkout link, for example <code>i42as__Checkout_Link__c</code>. <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. The action also adds quoteId, opportunityId, contactId, accountId and userId to the tracking.</td><td>false</td></tr><tr><td>expiresAfter</td><td>specifies expiration time of the link<br>in format 'days/hours/minutes' (for example '2/2/0' for 2 days and 2 hours, or '0/0/0' for expired). Can be assigned based on a parent Opportunity Close Date.</td><td>false</td></tr><tr><td>updateTag</td><td>The shop path for update links. Default <code>update</code>.</td><td>false</td></tr><tr><td>generateAsync</td><td>Default true. With the default, <strong>success</strong> is true when the job starts. Set false to generate the links in the same transaction. Then <strong>success</strong> tells you if the links were saved. Salesforce does not allow a callout after a record change in the same transaction. Thus, in a record-triggered flow, keep the default.</td><td>false</td></tr></tbody></table>

{% hint style="info" %}
The format for **customFieldsJson** is detailed in the following article: [Custom Fields](https://docs.limio.com/salesforce/setting-up/additional-config/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" %}
With **generateAsync** set to true (the default), a successful response indicates that link generation was initiated. Actual link creation and field population occur **asynchronously**. With **generateAsync** set to false, **success** is the result of the link generation.
{% 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**, **Long Text Area** 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.limio.com/salesforce/cpq/generate-links-from-apex.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
