# Related List Structure

## Model:

```
<!--{{!
<lineitemsSOQL>
<class>table892</class>
<soql>select name, amount, custom_field__c from opportunity order by id desc limit 30</soql>
<column>name</column>
<column>amount</column>
<column>custom_field__c</column>
</lineitemsSOQL>
}}-->
```

{% stepper %}
{% step %}
**`<!--{{!` and `}}-->`**

**Purpose**

S-Docs processing block markers

* `<!--{{!` tells S-Docs: *Start processing this block as S-Docs markup*
* `}}-->` tells S-Docs: *Stop processing S-Docs markup*

They also appear as HTML comments so the content isn’t visible if the template is loaded elsewhere.
{% endstep %}

{% step %}
**`<lineitemsSOQL>`**

**Purpose**

This tells S-Docs to execute **Direct SOQL** — a runtime SOQL query — and render the results in the document.

Key traits:

* Runs a real SOQL query during **document generation**
* Not limited to objects related to the base record
* Useful for large datasets, filtering, grouping, and dynamic data retrieval
* Results are used to build rows in a table (unless `<class>none</class>` is used)

This is the core wrapper around all parts of your related list code.
{% endstep %}

{% step %}
**`<class>`**

**Purpose**

Specifies the **CSS class** applied to the generated table.

* S-Docs uses classes like `table1`, `table892`, etc., to apply default table formatting
* You can style this class in the template’s stylesheet
* If you don’t want a table, set:\
  `<class>none</class>`\
  (then S-Docs outputs plain text values without a table wrapper)

This controls **presentation**, not data.

```
<style type="text/css">table.table892 {border:solid black 1px; border-collapse:collapse; border-spacing:0px;font-family:Arial Unicode MS,sans-serif; font-size:8pt; width:99%;margin-left:1px;}
  	.table892 tr {page-break-inside:always;margin-top:1px;}
	.table892col0, .table892col1, .table892col2 {border:solid black 1px;text-align:left;font-weight:normal;font-size:8pt;font-family:Arial Unicode MS,sans-serif;height:22px;}
</style>
```

{% endstep %}

{% step %}
**`<soql>`**

**Purpose**

Defines the **exact Salesforce SOQL query** S-Docs should run.

Your example:

```
<soql>select name, amount, custom_field__c from opportunity order by id desc limit 30</soql>
```

This retrieves:

* the 30 most recent Opportunities
* sorted by Id descending
* returning the fields: Name, Amount, Custom Field

In a Direct SOQL block:

* `<soql>` overrides `<ListName>` and `<where>` if they exist
* It supports aggregates (`SUM`, `COUNT`), subqueries, GROUP BY, ORDER BY, etc.
* S-Docs merge fields can be included in SOQL queries

Use this tag to ensure specific/advanced data retrieval.
{% endstep %}

{% step %}
**`<column>`**

**Purpose**

Each `<column>` defines **one column** in the generated output table.

Example:

```
<column>name</column>
```

This tells S-Docs:

* For each row returned from the SOQL query
* Pull the `name` field
* Display it as a table column (in order listed)

**Columns must match the SOQL fields or aliases.**

For example:

```
<column>amount</column>
<column>custom_field__c</column>
```

Optional attributes you could use:

* `format-number="#"`
* `format-date="M/d/yyyy"`
* `prefix="$"`
* `postfix=" units"`
* `replaceall="value1,replace1,value2,replace2"`
* `colspan="2"`

These control table layout and formatting.
{% endstep %}
{% endstepper %}

***

## Summary Table

| Tag                 | Meaning                                                   |
| ------------------- | --------------------------------------------------------- |
| `<!--{{!` / `}}-->` | S-Docs processing block markers                           |
| `<lineitemsSOQL>`   | Starts a Direct SOQL block (run real SOQL)                |
| `<class>`           | Styling for the generated table (use `none` for no table) |
| `<soql>`            | The actual SOQL query S-Docs executes                     |
| `<column>`          | Defines each output column in the result table            |

## Full Example:

```
<style type="text/css">table.table892 {border:solid black 1px; border-collapse:collapse; border-spacing:0px;font-family:Arial Unicode MS,sans-serif; font-size:8pt; width:99%;margin-left:1px;}
  	.table892 tr {page-break-inside:always;margin-top:1px;}
	.table892col0, .table892col1, .table892col2 {border:solid black 1px;text-align:left;font-weight:normal;font-size:8pt;font-family:Arial Unicode MS,sans-serif;height:22px;}
</style>
<table class="table892">
	<thead>
		<tr>
			<th class="table892header">name</th>
			<th class="table892header">amount</th>
			<th class="table892header">custom_field__c</th>
		</tr>
	</thead>
	<tbody><!--{{!
<lineitemsSOQL>
<class>table892</class>
<soql>select name, amount, description from opportunity order by id desc limit 30</soql>
<column>name</column>
<column>amount</column>
<column>custom_field__c</column>
</lineitemsSOQL>
}}-->
	</tbody>
</table>
```


---

# 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://help.sdocs.com/developer-hub/template-configuration-and-styling/related-list-references/related-list-structure.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.
