Queries are powerful tools that help you access your data. The query editor is an intuitive interface that makes creating queries a lot simpler. This page explains how to use the query editor to create an a!queryRecordType() or a!queryEntity() expression.
For examples of queries, see Query Recipes.
To create an a!queryRecordType()
expression using the query editor:
a!queryRecordType()
expression.To open the query editor:
The query editor will open and let you select your data source.
Tip: You can also open the query editor in other ways as you are building an expression rule or interface.
To select a record type:
For Record Type, search for the name of your record type and select the one you want to query.
Note: You cannot select a record type that uses a process model as the source, or a record type that uses a web service as the source and does not have data sync enabled.
By default, the Data Preview displays a preview of the data available in the record type.
Click Record Type Relationships to see the relationships available in the record type.
The fields section allows you to select which fields will be returned from your query.
By default, the query editor fetches all record fields from the base record type. You can choose to remove certain fields or add related record fields from your record type relationships.
For performance reasons, you should only query the fields that you need. If you query all of the fields, it may take longer for your query to run.
Select the fields to query by doing one or more of the following in the fields section:
The Aggregate section allows you to apply groupings and measures in your query.
Groupings allow you to group fields by a common value, while measures allow you to calculate the values in certain fields.
For example, you may want to show the number of orders that are in a given status like "Open" or "Shipped" using a grouping. If you want to know the total amount of sales for each status, you can add a measure to the aggregation. You can also add a measure filter to limit the results of that calculation.
To aggregate record data:
From the Performing Aggregations pane, click AGGREGATE RECORDS.
For example, the image below uses two groupings and a measure to return the count of employees with a certain title in each department.
You can reference rule inputs and local variables when you configure a filter or a data limit in your query. You can create rule inputs directly from the query editor, but if you need to use local variables, you'll need to configure those before opening the query editor.
To create a rule input from the query editor:
Configure the following properties:
Property | Description |
---|---|
Name | The name that is used when referencing the input within the rule definition, such as ri!input, or when passing arguments by keyword. Input names are case insensitive and must be unique within a given rule. |
Type | The data type of your rule input. |
Array | Whether the rule input should be a single value or an array of values. |
Expression | Define the value of your rule input by providing an expression. |
Value | Enter a static value to define your rule input. If you provided an expression, then this will populate with the results of the expression. |
Once you configure a rule input, it will appear in a dropdown when you configure a filter or data limit using the Input/Variable option.
The Filters section allows you to specify which results to return from your query based on conditions you specify.
The query editor allows you to easily set up filters using four criteria: Field, Condition, Value, and Apply Filter. Filters are evaluated in order starting with the first filter in the list. By default, the AND
operator is used to combine the filters, but you can change this to OR
in Expression mode.
If you want to skip filters that have an empty value, select the Ignore Filters with Empty Values checkbox. See a!queryLogicalExpression() page for more information on ignoring filters with empty values.
To create a filter:
From the Filtering Records pane, click Add filter.
Tip: Use Apply Filters in situations where you want to apply the filter only if a particular condition is met. For example, if the user belongs to a specific group.
For example, the image below filters a query so that it only returns cases that have a priority level of "Critical" and were closed in the last month.
If you need more advanced filters or want to change the evaluation operator, select Expression to specify your filters as an expression. For additional information on specifying filters as an expression, see a!queryLogicalExpression() and a!queryFilter().
The Sort and Limit section allows you to determine the order of the results with sorting and set a limit on the number of records you retrieve from the query.
By default, sorting and limiting is configured using a Guided experience. If you need more advanced sorting or data limits, click Expression to configure an expression. For additional information on specifying the sorting and data limit as an expression, see a!pagingInfo().
To configure how the data is sorted:
To add another field to sort by, click Add sorting field below.
To configure a data limit:
In the Sorting and Limiting Data section, add a Data Limit by entering a number or using the context menu to choose a rule input, variable, or constant.
Tip: The default limit of the query is 100 records, but you can specify a limit from 1 to 5000. The default startIndex is 1
, and this parameter can be changed in Expression mode.
The Query Results Preview contains three options to select which properties will be returned by the generated query.
Select one of the following properties:
After selecting your fields, you can arrange the order of the fields or remove any not needed for the result.
To organize the fields:
Click Remove to remove the field from the query.
You can preview the results of your query by clicking TEST QUERY.
Tip: The preview only shows 10 records at a time. This may differ from the number of records per page in the Data Limit section as it is only intended to be a preview.
If the query filters out all data, Query returned no data appears in the preview grid.
If the result of the test query is correct, click GENERATE QUERY to generate the a!queryRecordType()
expression.
There are six basic steps to creating an a!queryEntity()
using the query editor:
To open the query editor:
The query editor will open and let you select your data source.
Tip: You can also open the query editor in other ways as you are building an expression rule or interface.
In order to query a data store entity, you must first create a constant of type Data Store Entity that points to it. See Constants for additional information.
To select a data store entity:
By default, the Data Preview displays a preview of the data available in the data store entity.
If you want to use rule inputs for any of the settings in the query editor, you can create new rule inputs or edit existing ones directly from the query editor. You can use the query editor to change the test values of your rule inputs to test and troubleshoot your query.
To create a rule input from the query editor:
Configure the following properties:
Property | Description |
---|---|
Name | The name that is used when referencing the input within the rule definition, such as ri!input, or when passing arguments by keyword. Input names are case insensitive and must be unique within a given rule. |
Type | The data type of your rule input. |
Array | Whether the rule input should be a single value or an array of values. |
Expression | Define the value of your rule input by providing an expression. |
Value | Enter a static value to define your rule input. If you provided an expression, then this will populate with the results of the expression. |
Interfaces typically have many local variables whose state can change as you interact with them. With the query editor you can configure test values for these local variables and function variables. This gives you the flexibility to test your queries at any point in time.
These test values will only apply the values while in the query editor; after you click GENERATE QUERY, any changes you make will be reset.
To update a test value for a variable:
At the top of the query editor, click VARIABLES.
Note: This button only appears when you have existing local variables configured in your expression rule or interface.
Edit the Test Value for the local or function variable.
The query editor allows you to select the paging and sorting parameters in Basic mode using configurable fields. You can set limits on the amount of rows you retrieve and determine the order of the rows with paging and sorting.
To configure the page size, do one of the following:
To configure how the data is sorted:
To add another field to sort by, click Add Sort.
If you need more advanced paging and sorting settings, select Expression to configure additional settings. For additional information on specifying paging and sorting as an expression, see a!pagingInfo().
Tip: The default page size of the query is 50 rows per page and the default startIndex parameter is 1. You can change the startIndex parameter in Expression mode.
Filters allow you to select which results to return from your query based on conditions you specify. The query editor allows you to easily set up filters using four criteria: Field, Condition, Value, and Apply Filter.
By default, the query skips filters that have an empty value. If you don't want to skip these, clear the Ignore Filters with Empty Values check box. See a!queryLogicalExpression() for more information on ignoring filters with empty values.
To create a filter:
Note: Use Apply Filters in situations where you want to apply the filter only if a particular condition is met. For example, if the user belongs to a specific group.
See the following image for the location of each step in the user interface.
If you need more advanced filter options, select Expression to create your filters manually. For additional information on specifying filters as an expression, see a!queryFilter().
The Fields section allows you to select which fields will be returned from your query.
By default, the query editor fetches all fields so designers can see a query preview with all available fields. For performance reasons, you should configure the query to only return the fields that you need. If you query all of the fields, it may take longer for your query to run.
To change the fields in your query, do one or more of the following:
The query results preview lets you arrange the order of the fields, define aliases for fields, and configure visibility.
When grouping data, aliases are automatically created for calculated columns. Edit Alias allows you to change these generated names, and you can also change the alias for any field using this feature.
Visibility defines whether or not to show a column based on if a particular condition is met (for example, if the user viewing the query result belongs to a specific group).
To organize and configure a field, click the column's context menu and then do one or more of the following:
Note: If false
, the data for the field will not be retrieved from the database. An icon will display next to the column header and the data for the column will not display.
The query editor allows you to group your data or perform calculations on it to maximize the usefulness of results. You can calculate the sum, average, minimum, maximum, or count, and you can group your data by month, year, or date.
Clicking GROUP DATA removes the currently selected fields from the query but keeps the values for the Paging & Sorting and Filters sections.
To group your data:
If you select a column with a Number (Integer) or Number (Decimal) data type, you can choose to calculate sum, average, min, max, or count.
If you select a column with a Date or Date and Time data type, you can choose to show the count or group by month or year.
If you select a column with a Text data type, you can choose to show the count of each unique value.
When your data is grouped, you can select a field more than once. For example, you can add a field with a Date data type twice to group by year then month.
The fields display an icon that indicates which fields are used for grouping, as well as which calculations are used in numeric fields.
After the data is grouped, REMOVE GROUPING appears next to TEST QUERY. Clicking this button will remove any grouped or calculated fields. All filters will remain.
You can preview the results of your query by clicking TEST QUERY. If Fetch total row count is selected, a parameter will be applied to the query that retrieves the total number of rows that are returned by the query.
Tip: If selected, Fetch total row count is applied to the generated query, not just the preview. If you have a lot of data, it is recommended to turn off Fetch total row count to improve performance.
The query preview only shows 10 rows at a time. This may differ from the number of rows per page in the Paging & Sorting section as it is only intended to be a preview.
If the query filters out all data, Query returned no data appears in the preview grid.
Using the Query Editor