Playground is designed to check the validity of data and expressions you built.
The result of the expression you have at the end is the same that appears in the document after the template is generated. So, Playground helps you simulate what happens when the document is merged. Moreover, you can edit the GraphQL Query and Variables in the same tab to see how it affects the expression results. You can also execute the query you have to get the context that your Document Template will use when you start generating your documents.
You can find Playground in the "Maven Documents" application next to Query Builder. Click on the corresponding tab and you’ll see what we are talking about.
Playground consists of five separate sections:
Each section is a separate piece of functionality, which we will describe in the corresponding articles below. By the way, the headers of sections are clickable and lead to the similarly named sections on this document.
The "Query", "Variables", and "Context" sections have the text folding feature. It means you can click the black down arrow on the right pane of each section and hide the text under the header category.
In this section, you will find the same query as you have in Query Builder. There is no need to switch between the tabs to check objects and fields included in the query. If you make changes in Query Builder, they are displayed in Playground. Click the "Refresh" button in the top right corner of the "Query" section and the query will be updated.
The "Refresh" button plays an important role in updating data in the "Playground" tab. If you make changes in the "Query Builder" tab, you use this button to have everything up-to-date in Playground. It is also possible to click on the "Query" section and press Ctrl+Enter on the keyboard
So here and further in the text, by the "Refresh" button we mean the button in the Playground's "Query" section.
Besides, you can manually edit the query right in the "Query" section as well. Place the cursor in the query and delete, add, or edit fields. These changes are only valid in Playground and don't affect the query in Query Builder. You can discard everything by clicking Refresh.
The "currentuserId" variable is automatically populated with the ID of the user who is using Playground.
As we mentioned earlier, values in Variables influence the context, and Context influences the result of the expression. You can get the required context by assigning corresponding values to the corresponding variables. As mentioned above, the currentuserId variable is already populated. One more thing to do is to copy and paste the ID of the record from Salesforce into the "recordId" variable instead of the "{!recordId}" value.
This section holds the result data of the query execution.
Only a few steps are needed to make it happen:
It is possible to get context without changing the "recordId" variable. It just won't display information about the query filtered with the "recordId" variable.
It is important to remember, that every time anything was edited in the query or variables, the context should be refreshed
In the blink of an eye, all the information about the chosen record will be shown in the respective section. We mean it: the data appears fast. To prove our words, we added the execution time mark in the bottom right corner of the "Context" section.
Code Wrap is disabled in the "Context" section that helps you to have a clearer view of the data.
Notice, that if Global Variables are defined, they will appear in the "Context" section after you refresh it.
The "Context" section will also show you the data on custom queries if you have them in the document solution.
One more thing. You can easily edit displayed information right in the "Context" section. It means that you can correct or modify data in the context to influence the result of the expression you built. Be aware of these changes only last until you refresh the context. These modifications in Context won't change data in Salesforce. Do you remember? What happens in Playground stays in Playground.
If you make changes in Salesforce and want them reflected in Playground, for example, you've changed locale or time zone settings, it is necessary to reload the Playground's page. Refreshing the context or query won't be enough.
But if you made changes in the query or variables in the "Playground" tab and want these changes to modify the context, you need to click the "Refresh Context" button.
This is why we are all here: this section is all about creating expressions. Here you can write expressions manually or use the help of Expressions Builder. It helps you to construct expressions by pointing and clicking. You can find more information on Expression Builder in the corresponding article in the documentation.
How to write expressions manually doesn't need explanation: you are typing symbols using the right syntax in the "Expression" section. Using Expression Builder is something different. Let's build the following expression {!$groupBy(Opportunity[0].OpportunityLineItems,'Quantity','OpportunityLineItem')}
to group products from Opportunity by quantity. Here is the quick instruction:
Click on the icon in the top right corner of the "Expressions" section. It opens Expression Builder.
First of all, you can see all the available functions in the "Select function" menu. The first dropdown menu filters functions by categories (date, number, string, etc.), and the second dropdown menu contains filtered functions you can use.
You can also insert your Salesforce fields into expressions by using the "Select Object or Field" menu. Select the needed field (an arrow (>) next to a field suggests that it's a relationship field - e.g. Account > Contact > ...) and click the "Insert Object or Field" button.
Before inserting the function or a field, verify that you've selected the text you want to replace in the text field below.
From the "Select function" menu, choose the function and then choose the function type. Click Insert.
If needed, replace some parts of the function with Salesforce fields, other function types, or data.
Click Insert Expression. This inserts the expression back into the "Expression Builder" view. Click Insert Expression to insert it into the "Expression" window. That is how you create an expression.
After you have the body of the expression and the context it can use, you can start the process of evaluating that expression with just one click on the Evaluate button next to the "Expression Builder" button. You can evaluate the expression by pressing Ctrl+Enter on the keyboard as well.
Multiple expressions can be evaluated at a time.
If Global Variables are defined, you can simply write them down in the "Expression" section and click Evaluate Expression or press Ctrl+Enter. The value from the variable appears in the "Result" section.
The last section to describe is called Result. It represents the result of the expression you've built and evaluated.
For example, the result of the expression that we've built in the previous section is going to look like this:
If the "Result" section stays empty after you click the "Evaluate" button, please contact support.
Notice, that this section has the time mark as well, so you will know how long the expression was evaluated.
If the expression contains an error or wasn’t built properly, you’ll get an error message with a description of the problem.