> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/projects/use-cases/boards-and-pipelines/field-service-dispatch-queue-lwc.md). Agents can also search and read this documentation through its [MCP server](https://docs.avonnicomponents.com/~gitbook/mcp).

# Build a Salesforce Field Service Dispatch Queue with Avonni LWC

Assign unstaffed field jobs from a queue and see them on a technician schedule. Requires Avonni LWC Components and a field-job object with scheduled times and a technician field.

<figure><img src="https://3857391697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdHOej9Pd5IxJNGEJMZKW%2Fuploads%2FLSaVOArBh6d4mZePoNtT%2Fdispatch-queue-cover.jpg?alt=media" alt="Field Service Dispatch Queue in Salesforce Lightning, with unassigned jobs in Avonni Data Table and scheduled jobs in Avonni Scheduler."><figcaption></figcaption></figure>

### Build the project

Choose how you want to build:

✨ **Build with AI** — Give your AI assistant a ready-to-use prompt.

🛠️ **Build it** — Follow the steps yourself.

{% tabs %}
{% tab title="Build with AI" icon="wand-magic-sparkles" %}
{% stepper %}
{% step %}

#### Set up the assistant and sandbox

Follow [Build with AI](https://docs.avonnicomponents.com/build-with-ai) and use the `avonni-lwc-components` skill. Work in a Salesforce sandbox with Avonni LWC Components installed. Use the same four sample jobs as the manual build.
{% endstep %}

{% step %}

#### Copy the prompt

{% code title="Dispatch Queue build prompt" collapsedlinecount="10" %}

```

Build a Lightning app page workspace using Avonni Data Table and Scheduler inside one LWC. Verify query, mappings, selectrows and refresh against the Avonni MCP. Inspect the sandbox for Field_Job__c or an equivalent object, plus the job name, start, end and writable technician field. Show the field mapping and target sandbox before generating files.



Use the Data Table to list jobs with no technician and allow one row to be selected. Use Scheduler to show assigned jobs on a day timeline, grouped by technician. Add an explicit Assign selected job button. Save with Salesforce UI API and let Salesforce enforce permissions and validation. After a successful save, refresh both Avonni views. After a refused save, show the error and keep the job in the queue. Use one query scope and the same sample date for both views.



Test a successful assignment, a rejected assignment, and clear feedback in the sandbox. Verify the stored technician value and both UI views. Stop before deployment to production.

```

{% endcode %}
{% endstep %}

{% step %}

#### Review and test the workspace

Verify that the queries share the same job scope and that only one record is passed to Salesforce per click. Deploy to the sandbox and run [Try it](#try-it).
{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="Build it" icon="screwdriver-wrench" %}
{% stepper %}
{% step %}

#### Prepare the sandbox

Install [Avonni LWC Components](https://docs.avonnicomponents.com/lwc-components/getting-started/installation-and-licenses-management). Use `Field_Job__c` with a text `Name`, Date/Time fields `Start__c` and `End__c`, and a nullable text field `Technician__c`. The dispatcher needs read access to the records and edit access to the technician field.

[Download the Salesforce DX starter](https://3857391697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdHOej9Pd5IxJNGEJMZKW%2Fuploads%2F0Zn6S3GUJdoq3Hdk9Rk7%2Fdispatch-queue-lwc-starter.zip?alt=media). Create or map the object and fields before deploying the starter. The included validation rule applies to the sample electrical inspection and rejects Maya Chen for that job.

{% code collapsedlinecount="10" %}

```sh

sf project deploy start --source-dir force-app --target-org <sandbox-alias> --wait 5

sf apex run --file data/seed.apex --target-org <sandbox-alias>

```

{% endcode %}

Use **Text** for `Technician__c` and keep it optional. Create the object and three fields before deploying. The starter supplies the wrapper, seed script and certification validation rule. Seed the sandbox once. The two unassigned jobs are Pump inspection and Electrical inspection.
{% endstep %}

{% step %}

#### Build the unassigned queue with Avonni Data Table

Open `force-app/main/default/lwc/avonniDispatchQueue`. Put this in `avonniDispatchQueue.html`. `key-field="Id"` makes the selected key a Salesforce record ID. `max-row-selection="1"` limits the dispatcher to one job.

{% code overflow="wrap" collapsedlinecount="10" %}

```html
<avonni-dd-datatable
    header-title="Unassigned jobs"
    key-field="Id"
    query={queueQuery}
    columns={columns}
    max-row-selection="1"
    onselectrows={handleSelection}
></avonni-dd-datatable>
```

{% endcode %}

In `avonniDispatchQueue.js`, put `baseQuery` and `jobs` above the class. Add `queueQuery` and `columns` to the class. The name prefix limits both queries to the seed data. The `null` filter puts only unassigned jobs in the queue.

{% code overflow="wrap" collapsedlinecount="10" %}

```javascript
const baseQuery = {
    objectApiName: 'Field_Job__c',
    orderBy: 'Start__c ASC',
    limit: 25
};
const jobs = "Name LIKE 'Dispatch Queue Demo %'";
```

{% endcode %}

{% code overflow="wrap" collapsedlinecount="10" %}

```javascript
queueQuery = { ...baseQuery, filter: `${jobs} AND Technician__c = null` };

columns = [
    { fieldName: 'Name', label: 'Job', type: 'text', wrapText: true },
    { fieldName: 'Start__c', label: 'Starts', type: 'date' }
];
```

{% endcode %}
{% endstep %}

{% step %}

#### Map assigned jobs into Avonni Scheduler

Put the Scheduler next to the queue in the same HTML template. The day timeline uses the fixture date November 16, 2026. `resourceName` groups the jobs by the technician text field. `name` identifies each event by its Salesforce ID.

{% code overflow="wrap" collapsedlinecount="10" %}

```html
<avonni-dd-scheduler
    header-title="Technician schedule"
    variant="timeline"
    variant-attributes={timelineOptions}
    selected-date={day}
    selected-time-span-name="Standard.Scheduler.DayTimeSpan"
    query={scheduleQuery}
    mapping={scheduleMapping}
></avonni-dd-scheduler>
```

{% endcode %}

Add these properties to the wrapper class. The two complementary filters determine where each job appears. Scheduler reads start and end times from `Start__c` and `End__c`.

{% code overflow="wrap" collapsedlinecount="10" %}

```javascript
day = '2026-11-16T12:00:00Z';
timelineOptions = { zoomToFit: true };
scheduleQuery = { ...baseQuery, filter: `${jobs} AND Technician__c != null` };

scheduleMapping = {
    title: '{{Record.Name}}',
    name: '{{Record.Id}}',
    resourceName: '{{Record.Technician__c}}',
    startDate: '{{Record.Start__c}}',
    endDate: '{{Record.End__c}}'
};
```

{% endcode %}

<figure><img src="https://3857391697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdHOej9Pd5IxJNGEJMZKW%2Fuploads%2FLSaVOArBh6d4mZePoNtT%2Fdispatch-queue-cover.jpg?alt=media" alt="Field Service Dispatch Queue in Salesforce Lightning, with unassigned jobs in Avonni Data Table and scheduled jobs in Avonni Scheduler."><figcaption><p>Salesforce starts with two unassigned inspections on the left and the seeded jobs on the Maya Chen and Tomas Berg rows on the right.</p></figcaption></figure>
{% endstep %}

{% step %}

#### Save the selected assignment and refresh both queries

Use the Salesforce `lightning-combobox` and `lightning-button` below the queue. `selectrows` comes from Avonni Data Table. Its `selectedRowsKeyValue` array supplies the record ID. The standard Combobox `change` supplies the technician. The assignment button stays disabled until both inputs are present.

{% code overflow="wrap" collapsedlinecount="10" %}

```html
<lightning-combobox
    label="Technician"
    options={technicians}
    value={technician}
    onchange={handleTechnician}
    disabled={saving}
></lightning-combobox>
<lightning-button
    class="slds-m-top_small"
    label="Assign selected job"
    variant="brand"
    onclick={assign}
    disabled={assignDisabled}
></lightning-button>
```

{% endcode %}

Define the technician options and save state in `avonniDispatchQueue.js`. Use the same technician labels for the Scheduler’s resource rows and the combobox values.

{% code overflow="wrap" collapsedlinecount="10" %}

```javascript
technicians = [
    { label: 'Maya Chen', value: 'Maya Chen' },
    { label: 'Tomas Berg', value: 'Tomas Berg' }
];

selectedId;
technician;
saving = false;
status;
error;
```

{% endcode %}

{% code overflow="wrap" collapsedlinecount="10" %}

```javascript
get assignDisabled() {
    return this.saving || !this.selectedId || !this.technician;
}

handleSelection(event) {
    this.selectedId = event.detail.selectedRowsKeyValue[0];
}

handleTechnician(event) {
    this.technician = event.detail.value;
}
```

{% endcode %}

Import `updateRecord` from `lightning/uiRecordApi`. The wrapper saves `Technician__c` through Salesforce, then calls Avonni’s `refresh()` on each view. A rejected Salesforce update leaves the selection available and shows the first validation or permission error.

{% code overflow="wrap" collapsedlinecount="10" %}

```javascript
async assign() {
    if (this.assignDisabled) return;

    this.saving = true;
    this.status = undefined;
    this.error = undefined;

    try {
        await updateRecord({
            fields: { Id: this.selectedId, Technician__c: this.technician }
        });
    } catch (error) {
        const output = error.body?.output;
        this.error = output?.errors?.[0]?.message ??
            Object.values(output?.fieldErrors ?? {}).flat()[0]?.message ??
            error.body?.message ?? 'The job could not be assigned.';
        this.saving = false;
        return;
    }

    this.selectedId = undefined;
    this.technician = undefined;
    this.status = 'Job assigned.';
    try {
        await Promise.all([
            this.template.querySelector('avonni-dd-datatable').refresh(),
            this.template.querySelector('avonni-dd-scheduler').refresh()
        ]);
    } catch {
        this.error = 'Salesforce saved the assignment. Reload the workspace to refresh the views.';
    } finally {
        this.saving = false;
    }
}
```

{% endcode %}

If the save succeeds and a refresh fails, Salesforce already has the technician. Reload the workspace to reconcile the display.

Place these status messages below the two views in `avonniDispatchQueue.html` so a successful assignment and a rejection are both visible.

{% code overflow="wrap" collapsedlinecount="10" %}

```html
<p lwc:if={status} class="slds-m-top_small" role="status">{status}</p>
<p lwc:if={error} class="slds-m-top_small slds-text-color_error" role="alert">{error}</p>
```

{% endcode %}
{% endstep %}

{% step %}

#### Open the Lightning page and replay both outcomes

In Lightning App Builder, add **Field Service Dispatch Queue** to a sandbox App Page, save and activate it for your test audience. You can also open `/lightning/cmp/c__avonniDispatchQueue` on the sandbox’s Lightning domain.

As the dispatcher, assign Pump inspection to Maya Chen. Check that it leaves the queue and appears on Maya’s row without a page reload. Try assigning Electrical inspection to Maya. Check that Salesforce shows the certification error and the job stays unassigned.

As a read-only user, try the otherwise valid Tomas Berg assignment on Electrical inspection. Expect a permission error and the same queue and schedule. On a separate run with edit access, repeat it and check that Electrical inspection now appears under Tomas.
{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

### Try it

1. Check that **Pump inspection** and **Electrical inspection** are in the queue and that the Scheduler shows Maya Chen and Tomas Berg.
2. Assign **Pump inspection** to Maya Chen. Check that it leaves the queue and appears on Maya’s row without reloading Lightning.
3. Try assigning **Electrical inspection** to Maya Chen. Check that Salesforce shows the certification error, the job stays in the queue, and the Scheduler shows no new job for it.

**Sandbox result.** In Salesforce Lightning, a sandbox admin assigned Pump inspection to Maya Chen. The queue and the Scheduler updated without a page reload. Salesforce refused the electrical inspection, and the job stayed in the queue. A record check confirmed that Pump inspection saved Maya Chen and Electrical inspection still had a blank technician.

**Read-only sandbox test.** Sign in as a user with Read permission and no Edit permission on Field Job. Select Electrical inspection, choose Tomas Berg, and click Assign selected job. In the sandbox, Salesforce rejected the save and Lightning displayed “entity type cannot be updated: Field Job”. Without reloading the page, Electrical inspection stayed in the queue and the same three jobs stayed on the schedule. A before-and-after check of the four Salesforce records confirmed that Electrical inspection stayed unassigned and the other jobs kept their technicians and time slots.

**Assignment with edit access.** Repeat the same assignment while Electrical inspection is still unassigned, using a user who can edit the job and its Technician field. In the sandbox, Lightning displayed “Job assigned.” Without reloading, the job left the queue and appeared under Tomas Berg in the Scheduler. The other three jobs stayed at their original times. A Salesforce record check confirmed that Tomas Berg was saved as the technician.

### Component references

* [Data Table](https://docs.avonnicomponents.com/lwc-components/data-driven-components/datatable)
* [Scheduler](https://docs.avonnicomponents.com/lwc-components/data-driven-components/scheduler)


---

# 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.avonnicomponents.com/projects/use-cases/boards-and-pipelines/field-service-dispatch-queue-lwc.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.
