Mastering Get Elements in Salesforce SOQL Queries

Hello folks,
Let’s dive in to get elements this week. Get elements, a.k.a. SOQL queries, derive one or more values from the Salesforce database. These values can be used later in our flow.

Understanding Variables

Before we go deeper into the get element, we need to talk about variables. Variables are containers in Salesforce that keep values for us temporarily until we use them. This is kind of like writing something on a napkin rather than in the address book. To save values permanently, we write them to the database; in other words, we write them in a record and save/commit to call and use them later. On the other hand, variables are available only in the flow we are in, and they vanish after we complete our flow interview.

Creating and Using Variables in Flows

In Salesforce flows, we create variables on the left panel in the resource manager, and some others are automatically created for us.

The Dynamics of Record Variables

When we get a complete record, for example, Salesforce creates a record variable automatically and saves all the values of the get element in this variable.

Case Study: Get Account Example

Let’s assume we find only one opportunity record match in our get step labeled as “Get Account”. Salesforce auto-creates a get element record variable with all the field values that are available under that record. As flow makers, we can refer to one or more field values in that variable when we are building our flows – in this case {!Get_Account.Id} – for the recordId.

Executing a Successful Get Step


What are the parameters we need to set to execute a successful get step?

Typical scenario: We would like to find all Accounts with the name ACME.

Setup: Tell your get step you want to get a record of Account object type.

Set the filter condition as Account Name equals ACME.

Possible Outcomes of a Get Step

We may find:

  • No records
  • One record
  • More than one records

Let’s look at these possibilities:

No records: Your get step won’t fail. However, you will have a record variable automatically created with the value null assigned to it.

One record: You will have one record in your record variable complete with its recordId, name, and all other field values. You can use these later in your flow.

More than one record: You have options here. First, you can tell the get element whether you need to sort these records according to one field value. Then you can decide whether to get and assign the first record to a record variable or assign all the records to a collection variable (this means N number of containers of the same type). All these are auto-created for you.

Handling No Records Outcome

One important tip here is to catch the “No records” outcome. If you don’t do that and use the record variable later in your flow, you will receive an error message, and your flow will fail.

So insert a decision step right after your get element and check whether {!Get_Account} is null true. If that is the case, stop all operations and exit the flow gracefully. In screen flows, you can insert a screen element to show the user a message explaining what happened.

Conclusion

Use the filter criteria wisely because if your get element returns more than 50K records, you will hit the governor limit, and your flow will fail.

Recently published content: How do you extend upsell/crosssell offers using a screen flow on a Lightning page. Click here to this Salesforce San Francisco User Group Video on the Salesforce Break Youtube Channel to learn.

Do you need to see advanced use case flow applications for inspiration? Click here to watch the short video on a Loan Application Use Case.

Enjoy

P.S. Originally published on 11/22/2021.

Read the previous issue of the newsletter here.

Subscribe to the weekly educational Salesforce Flow Tips newsletter here.


Comments

6 responses to “Mastering Get Elements in Salesforce SOQL Queries”

  1. Gustavo Seluja Avatar
    Gustavo Seluja

    Very well explained Andy, thank you. Two totally unrelated questions. How did you create the emoji of you (I want one!). Second, what’s the background of your name, Engin Utkan (I’m interested in people’s names)

    1. Hello Gustavo, the emoji is done from a real picture, you can see the picture here https://medium.com/@gatortail/about . You can find artists that do this on freelancer platforms. I used bionluk.com (full disclosure: I am an angel investor). I am Turkish-American. My first name Engin means vast & broad as in knowledge. My last name Utkan means successful. As opposed to the famous dialogue in the movie Pulp Fiction, our names mean sonething in Turkish. Lol. Thanks for writing. And I am happy you liked this newsletter issue.

  2. […] If you don’t understand some of the concepts and the terms used in this newsletter issue, you may want to read get element issue here. […]

  3. […] If you don’t understand some of the concepts and the terms used in this newsletter issue, you may want to read get element issue here. […]

Leave a Reply

Discover more from Salesforce Break

Subscribe now to keep reading and get access to the full archive.

Continue reading