> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/additional-troubleshooting/related-lists-display-same-values-converting-lineitems-to-lineitemssoql.md).

# Use lineitemsSOQL for multiple filtered related lists

Avoid shared filter behavior when one template contains more than one filtered related list.

Use `lineitemsSOQL` when a template includes more than one filtered version of the same related list.

Legacy `<lineitems>` blocks can apply one filter to both lists. `lineitemsSOQL` keeps each filter separate.

### Problem

If one template contains multiple legacy related lists with different `<where>` clauses, both lists can render using the same filter.

This usually appears when you split one related list into separate sections, such as:

* hardware products
* service products
* open items and closed items

### Solution

Convert each legacy related list to its own `<lineitemsSOQL>` block.

Each block uses its own SOQL query, so each list keeps its own `WHERE`, `ORDER BY`, and `LIMIT` logic.

### What to change

{% stepper %}
{% step %}

### Change the tag name

Replace `<lineitems>` with `<lineitemsSOQL>`.
{% endstep %}

{% step %}

### Use the object name in the query

Query the Salesforce object in the `FROM` clause.

Use `OpportunityLineItem`, not the relationship name `opportunitylineitems`.

For custom objects, replace `__r` with `__c`.
{% endstep %}

{% step %}

### Link the query to the current record

Add a `WHERE` clause that ties the child object to the parent record.

Example: `WHERE OpportunityId = '{{!Opportunity.Id}}'`
{% endstep %}

{% step %}

### Select every displayed field

Any field you display in a `<column>` should also appear in `SELECT`.
{% endstep %}
{% endstepper %}

### Example conversion

This legacy related list filters Opportunity Products by product family.

{% code title="legacy-lineitems.xml" %}

```xml
<!--{{!
<lineitems>
  <listname>opportunitylineitems</listname>
  <where>PricebookEntry.Product2.Family = 'Hardware'</where>
  <column>PricebookEntry.Product2.Name</column>
  <column>Quantity</column>
  <column prefix="$" format-number="#,###.00">TotalPrice</column>
</lineitems>
}}-->
```

{% endcode %}

Convert it to `lineitemsSOQL` like this:

{% code title="lineitemssoql.xml" %}

```xml
<!--{{!
<lineitemsSOQL>
  <soql>
    SELECT PricebookEntry.Product2.Name, Quantity, TotalPrice
    FROM OpportunityLineItem
    WHERE OpportunityId = '{{!Opportunity.Id}}'
      AND PricebookEntry.Product2.Family = 'Hardware'
  </soql>
  <column>PricebookEntry.Product2.Name</column>
  <column>Quantity</column>
  <column prefix="$" format-number="#,###.00">TotalPrice</column>
</lineitemsSOQL>
}}-->
```

{% endcode %}

If you need a second list, create a second `lineitemsSOQL` block with its own `WHERE` clause.

For example, a second block could filter `Family = 'Services'` without affecting the first block.

{% hint style="info" %}
`lineitemsSOQL` is the right choice when one template needs multiple filtered views of the same related list.
{% endhint %}

### Key detail

`opportunitylineitems` is a relationship name. `OpportunityLineItem` is the object name.

That object name belongs in the SOQL `FROM` clause.

### Keep going

* Review [How to: Filter and Sort a Related List](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/how-to-filter-and-sort-a-related-list.md)
* Review [How to: Format and Summarize a Related List](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/how-to-format-and-summarize-a-related-list.md)


---

# 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://help.sdocs.com/sdocs/advanced-template-logic/related-lists/additional-troubleshooting/related-lists-display-same-values-converting-lineitems-to-lineitemssoql.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.
