Field Multiselect.


This feature allows using special keywords in the SOQL query in order to automatically select multiple SObject fields by desired criteria.

Table of Contents



Feature overview.

If you have a large amount of field in your SOQL query, this can become tedious to maintain. To help with this case we have added a set of the special multiselect keywords that you can add as a field into your SELECT query. Each keyword will be then replaced at runtime with real object fields according to the actual object metadata and these fields will be automatically injected into the query. This a quite similar to wildcards that can be used to select files in the computer file system.

Adding multiple keywords will allow you to select smaller subsets of fields, since they act as combined by the && (AND) operator. For example to select only the custom lookup fields use the following query: SELECT custom_true, lookup_true FROM Account

Use excludedFields property of ScriptObject to exclude certain fields from the query AFTER they were selected with multiselect keywords. Note , that excludedFields will also exclude fields even they are included in the query explicitly not by using the multiselect keywords.

The full list of the supported multiselect keywords:

all - selects all fields of the object.

readonly_true - selects all fields that are not creatable and not updatable, for example autonumber or formula.

readonly_false - the opposite to readonly_false.

custom_true or custom_false - to select only custom (custom = true) or standard fields respectively (custom = false)

standard_true or standard_false - to select only standard (custom = false) or custom fields (custom = true) respectively (it's the opposite to the custom_true / custom_false). custom_false and standard_true should give the same result.

createable_true or createable_false - to select only all createable fields (all fields having createable=true property of DescribeSObjectResult class) or negative.

updateable_true or updateable_false - to select only all updateable fields (all fields having updateable=true property of DescribeSObjectResult class) or negative.

lookup_true or lookup_false - to select only all lookup and master-detail fields or negative.

type_... - to select only the fields of the desired type, for example to select only the textual fields, use SELECT type_string FROM Account

The available types are the same as the DisplayType enum of the SFieldDescribeResult object and can be found here:

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_Schema_DisplayType.htm

You should spell the type starting from the lowcase letter, for example: type_string, type_boolean, type_currency, etc.


Below some examples of queries that leverages multiselect keywords feature:

/* Selects Id, Name and also all custom non-lookup fields of the Account */
SELECT Id, Name, custom_true, lookup_false FROM Account
/* Selects Id, Name and also all standard lookup/master-detail fields of the Account */
SELECT Id, Name, standard_true, lookup_true FROM Account
/* The below query will give the same result */
SELECT Id, Name, custom_false, lookup_true FROM Account
/* Selects Id, Name and also all createable fields of the Account */
SELECT Id, Name, createable_true FROM Account
/* Selects all fields of the Boolean type */
SELECT type_boolean FROM Account

Important note! Below the sobjects which lookups will not covered by the multiselect keywords and you need to add them manually to you query:

  • RecordType
  • Group
  • User
  • DandBCompany

For example, the Account.RecordTypeId field will not be included and processed when your query is: SELECT all FROM Account multiselect.

Last updated on 13th Apr 2024