# Create Order via Apex

**LFS version**: requires Limio for Salesforce LFS v12.23 or later

Limio for Salesforce exposes a global apex class for creating orders in Limio without the need for a UI being built on top. This allows for backend driven processes that don't require a UI to create an order in Limio.

The process consists of calling a global apex method exposed by a global class, the `LimioOrder_Acquisition`. The global method `processInvoiceLimioOrder` accepts a parameter of type `LimioOrder_Acquisition.OrderRequest` and processes the order accordingly.

Below is the list of parameters for the class

global class OrderRequest { global String country; global String offerPath; global String offerId; global Map\<String,object> tracking; global Map\<String,object> billingAddress; global Map\<String,object> deliveryAddress; global Contact contact; global String invoicePref; }

Each of these parameters must be populated as follows:

* `country`: 2 characters country ISO code, e.g. `GB`. Required
* `offerPath`: path of the offer, e.g. `/offers2/Digital offer`. Required if `offerId` is blank
* `offerId`: id of the offer, e.g. `XXXXX`. Required if `offerPath` is blank
* `tracking`: object containing customer identifiers. Required to link it to the relevant Salesforce record
* `billingAddress`: object containing billing address. Not required. For the full list of supported properties see the example provided below.
* `deliveryAddress`: object containing delivery address. Not required. For the full list of supported properties see the example provided below.
* `contact`: Salesforce contact, required for customer information. Must query the fields FirstName, LastName, Email. Required
* `invoicePref`: since the payment is invoice, this must contain either `Email` or `Post`. Required

Below is an example of how this method can be invoked to create a subscription in Limio:

```apex
Map<String, Object> billing = new Map<String, Object>();
billing.put('firstName', 'Test First Name');
billing.put('lastName', 'Billing');
billing.put('country', 'GB');
billing.put('address2', '');
billing.put('city', 'London');
billing.put('address1', '4 Leathermarket St, Weston St');
billing.put('buildingNumber', '4');
billing.put('streetName', 'Leathermarket St');
billing.put('postalCode', 'SE1 3ER');
billing.put('company', '');
billing.put('state', 'London');
billing.put('customFields', new Map<String, Object>());

Map<String, Object> delivery = new Map<String, Object>();
delivery.put('firstName', 'Test First Name');
delivery.put('lastName', 'Delivery');
delivery.put('country', 'GB');
delivery.put('address2', '');
delivery.put('city', 'London');
delivery.put('address1', '4 Leathermarket St, Weston St');
delivery.put('buildingNumber', '4');
delivery.put('streetName', 'Leathermarket St');
delivery.put('postalCode', 'SE1 3ER');
delivery.put('company', '');
delivery.put('state', 'London');
delivery.put('customFields', new Map<String, Object>());

Contact c = [SELECT id, firstName, lastName, email, accountId FROM contact LIMIT 1];

Map<String, Object> tracking = new Map<String, Object>();
tracking.put('contactId', c.id);
tracking.put('accountId', c.accountId);

i42as.LimioOrder_Acquisition.OrderRequest request = new i42as.LimioOrder_Acquisition.OrderRequest();
request.country = 'GB';
request.offerPath = '/offers2/Digital offer';
request.offerId = null;
request.tracking = tracking;
request.billingAddress = billing;
request.deliveryAddress = delivery;
request.contact = c;
request.invoicePref = 'Email';

Object result = i42as.LimioOrder_Acquisition.processInvoiceLimioOrder(request);
```

This apex method returns a generic apex `Object` in the following format:

```
{
  "external_id": "224f64b5-cc25-4eae-9959-33e6b1922aee",
  "id": "event-789bb1fc7456b11f1775ff19ffac5373",
  "order_reference": "3OJEOVOT2MM0",
  "owner": "id-a88bf1bda3c26cbf6e61d538ce423653",
  "status": "submitted"
}
```


---

# 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/setting-up-limio-for-salesforce/apex-classes/create-order-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.
