---
schema_version: "1"
id: e3ba294ec43c283104229bd0c45d204801f3c3ab1f4b2193e82b0587332cb1fb
title: WITH
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/knowledge/guides/sforce-api-calls-soql-select-with.md
canonical_url: https://developer.salesforce.com/docs/service/salesforce-knowledge-dev-guide/guide/sforce-api-calls-soql-select-with.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 04ebc5f6dae3b40b5b58f2cf3a9bf3ddad2d112cfacd3a216da1724e23d8926f
products:
  - Salesforce Knowledge Developer Guide
  - Service Cloud Developer Content
---
---

## title: "WITH"

description: "You can filter records based on field values, for example, to filter according to category or to query and retrieve changes that are tracked in a user’s profile feed by using WITH filteringExpression. This optional clause can be added to a SELECT statement of a SOQL query."
info_model_version: "sfdocs1"
app_area: Apex_Code_Development_Deployment Bulk_API REST_API SOAP_API Streaming_API Developer_Guide_Reference
ui_platform: aloha mobile sfx
role: Developer
edition: PE EE UE DE DBCOM PXE
topic_type: reference

# WITH

You can filter records based on field values, for example, to filter according to category or to query and retrieve changes that are tracked in a user’s profile feed by using `WITH {filteringExpression}`. This optional clause can be added to a `SELECT` statement of a SOQL query.

Unlike the `WHERE` clause, which only supports fields from the object specified in the `FROM` clause, `WITH` allows you to filter by other related criteria. For example, you can use the `WITH` clause to filter articles based on their classification in one or more data category groups. The `WITH` clause can only be used in the following cases:

- To filter records based on their categorization. See `[WITH DATA CATEGORY](https://developer.salesforce.com/docs/service/salesforce-knowledge-dev-guide/guide/sforce-api-calls-soql-select-with-datacategory.md)`.
- To query and retrieve record changes tracked in a user profile feed. See [Custom ObjectFeed](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_customobject__feed.htm) in the _Object Reference for the Salesforce Platform_.
- To filter records based on user access permissions on fields or objects being queried within Apex code. See [Filter SOQL Queries Using WITH SECURITY_ENFORCED](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_with_security_enforced.htm) in the _Apex Developer Guide_.
- To specify user mode access for Apex database operations. Apex code runs in system mode by default, which means that it runs with substantially elevated permissions over the user running the code. To enhance the security context of Apex, you can specify user mode access by using `WITH USER_MODE`. Field-level security (FLS) and object permissions of the running user are respected in user mode, unlike in system mode. User mode always applies sharing rules, but in system mode they’re controlled by sharing keywords on the class. See [Enforce User Mode for Database Operations](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_enforce_usermode.htm) in the _Apex Developer Guide_.

**note:** Salesforce recommends that you enforce field- and object-level security permissions by using `WITH USER_MODE` instead of `WITH SECURITY_ENFORCED` because it has fewer limitations.

If `WITH` is specified, the query returns only records that match the filter and are visible to the user. If unspecified, the query returns only the matching records that are visible to the user.

The filtering expressions in these statements are noted.

- `SELECT Title FROM KnowledgeArticleVersion WHERE PublishStatus='online' WITH DATA CATEGORY Geography__c ABOVE usa__c`
  - Where `WITH DATA CATEGORY Geography__c ABOVE usa__c` is the filter.
- `SELECT Id FROM UserProfileFeed WITH UserId='005D0000001AamR' ORDER BY CreatedDate DESC, Id DESC LIMIT 20`
  - Where `WITH UserId='005D0000001AamR'` is the filter.
