While working on any project based on Salesforce and using AccelQ to automate the flow, there are certain scenarios where we might need to use SOQL queries to get data instead of writing a script to get the data directly from the UI. It saves time and effort for QA Engineers. But before using the SOQL queries in AccelQ we need to understand how to set up properly and what are some of the basic approaches we can use.
How to Set Up?
Setting up AccelQ to execute the AccelQ queries is really simple, to start with we only need three things from any salesforce Org:
For URLs, we can use “https://login.salesforce.com” or “https://test.salesforce.com” depending on the type of environment. The same goes for the Username, we can use the username we enter while logging in to the org manually.
For the Password, we need to use the password we use to log in manually and the security token for the related salesforce org.
To obtain the security token from the salesforce, click on the user icon and then click on the settings right under the user name, then click on Reset the Security Token on the left side, you will receive an email including that security token.
Once we have all these things, we can head on to AccelQ and create an action to start working with SOQL queries.
Creating SOQL Action in AccelQ
After creating a new action, type “soql” and it will automatically show a few commands we can use. Let’s go through the first three statements as these are the most used ones.
- Define Salesforce Query Connection (SOQL/SOSL): We can use this statement to set up our connection.
Here, SOQL URL Instance, SOQL Username, and SOQL Password are global properties that we can use across orgs or differently for each org. We can use exact values for the URL and username except for the password. For the password, we need to use the Salesforce Org password+security token. While creating these global properties, we can encrypt the password directly with AccelQ tools and use that.
- Execute Salesforce Query: We use this statement to run the SOQL queries.
We can use the queries we use in the developer console on the salesforce here.
- Get Field Value from Salesforce Query Result: We can use this statement to get the results from an executed query.
We can use the query reference name to get the results from that query, we can use row number and column number to get the data from the results, and we can also use column name instead of column number. However, one limitation is that this statement will only record a single result so if we have multiple rows of results, we can use collection lists to store the data and then use it in the actions.
Some of the best Approaches:
- Use global properties from credentials so we don’t have to change actions directly every time we run the script in different orgs.
- If there are certain record types like in Accounts or contacts in salesforce that may have the same names, it is best to use the record Id.
- Use collection lists to store multiple rows of the SOQL query results.
- Always make SOQL actions separate from UI script actions to use the same SOQL actions within other actions
- Always make SOQL action a library action to use in any activity within any context.