Field Multiselect.


Table of Contents



Overview

Purpose: This feature simplifies SOQL query construction by allowing the use of special keywords to automatically include multiple SObject fields based on specific criteria. It is designed to enhance efficiency and maintainability of queries involving large sets of fields.

Feature Description

Constructing SOQL queries with many fields can become cumbersome and difficult to maintain. To address this, we have introduced multiselect keywords. These keywords can be included in the SELECT clause of a query, and are dynamically replaced at runtime with the actual object fields as per the object's metadata. This functionality is analogous to using wildcards in file systems for selecting files.

Using multiple keywords together will result in the selection of a smaller subset of fields, as the keywords are combined using an AND logic. For instance, to select only custom lookup fields, you could use: SELECT custom_true, lookup_true FROM Account.

Additionally, you can utilize the excludedFields property in the ScriptObject to exclude specific fields from the results even after they have been selected with multiselect keywords. This exclusion applies even if fields are explicitly included in the query not using multiselect keywords.

Supported Multiselect Keywords

Here is the complete list of supported multiselect keywords and their functions:

  • all - Selects all fields of the object.
  • readonly_true - Selects fields that are not creatable and not updatable (e.g., autonumber, formula).
  • readonly_false - Selects fields that are creatable or updatable.
  • custom_true / custom_false - Selects either custom (true) or standard (false) fields.
  • standard_true / standard_false - Selects either standard (true) or custom (false) fields (opposite to custom_true / custom_false).
  • createable_true / createable_false - Selects fields based on their creatability status.
  • updateable_true / updateable_false - Selects fields based on their updatable status.
  • lookup_true / lookup_false - Selects all lookup and master-detail fields or excludes them.
  • type_... - Selects fields of a specific type, such as type_string for textual fields. Type identifiers must start with a lowercase letter and match types in the DisplayType enum found in the Salesforce Developer Documentation.

Examples of Using Multiselect Keywords

Here are some example queries leveraging the multiselect keywords feature:

-- Selects Id, Name, and all custom non-lookup fields of the Account
SELECT Id, Name, custom_true, lookup_false FROM Account
-- Selects Id, Name, and all standard lookup/master-detail fields of the Account
SELECT Id, Name, standard_true, lookup_true FROM Account
-- This query gives the same result
SELECT Id, Name, custom_false, lookup_true FROM Account
-- Selects Id, Name, and all creatable fields of the Account
SELECT Id, Name, createable_true FROM Account
-- Selects all fields of the Boolean type
SELECT type_boolean FROM Account
Notes:
  • The following SObjects' lookup fields are not covered by the multiselect keywords and must be manually added to your query:

    • RecordType
    • Group
    • User
    • DandBCompany

    For instance, the field Account.RecordTypeId will not be included or processed when using the query: SELECT all FROM Account with multiselect.

Last updated on 23rd Apr 2024