Check if Get Records Is Empty in Salesforce Flow : Bijay Kumar

Check if Get Records Is Empty in Salesforce Flow
by: Bijay Kumar
blow post content copied from  SalesForce FAQs
click here to view original post



### Summary The content is a tutorial about creating a Salesforce Flow that automates the process of sending emails to contacts linked to an account. The key focus is on ensuring that the flow can handle cases where there are no matching records to avoid errors. Here's how the process works: 1. **Setting Up the Flow**: Begin by navigating to the 'Flows' section in the Salesforce setup and creating a new Record Trigger Flow based on 'Account' changes. 2. **Get Records Element**: Use the 'Get Records' element to find all contacts related to the account. Specify criteria to filter for the correct contacts. 3. **Decision Element**: Add a Decision element to check if any records were found. If records exist (the outcome is 'Not Empty'), the flow will proceed to send emails. If no records are found ('Empty'), the flow will end to prevent errors. 4. **Send Email Action**: If there are related contacts, a 'Send Email' action will execute to deliver the emails using specified values such as sender, subject, and recipient. 5. **Debugging**: Before activating the flow, always debug it to ensure it operates correctly. ### Key Details - **How to Handle Empty Records**: The critical part of the flow involves checking if the 'Get Records' element returns any records to avoid runtime errors. - **Flow Activation**: Debugging is essential to ensure the correctness and functionality of the flow before it goes live. ### Conclusion This tutorial shows how to efficiently manage potential errors in Salesforce Flow by checking for empty records and executing appropriate actions based on the outcomes. ### Additional Context Salesforce Flows are integral to automating tasks and improving efficiency in the Salesforce ecosystem. Understanding how to manage records effectively enhances process reliability. ### Hashtags for SEO #Salesforce #SalesforceFlow #AutomateEmails #GetRecords #EmailAutomation #NoErrorFlow #SalesforceTutorial #CRMAutomation #SalesforceAdmin #FlowManagement


I was developing a Salesforce Flow to automate the process of sending an email to all contacts associated with the account. For that, I retrieved the record using the ‘Get Record’ element and then added a ‘Send Email’ action to send the email to the retrieved records.

But what if the get record element doesn’t find matching records? That means it will be empty; then the flow can fail or throw an error.

That’s why it’s important to check if the Get Records result is empty before using the data in later steps.

In this tutorial, we will learn how to check if get records is empty in Salesforce Flow using an example and step-by-step explanation by adding the Get Records element.

Check if Get Records Is Empty in Salesforce Flow

Below, I will create a record trigger flow to automate the process of sending an email. There, I will explain how to check if the record is empty, and if it is not empty, then the flow will send.

If the get record doesn’t find a record, then we need to end the flow so that we won’t get any error; the flow execution will not be interrupted.

Navigate to the setup, and in the Quick Find box, search for ‘Flows’ under Process Automation.

In the flows setup window, click on the button New Flow -> Start From Scratch -> select the Record Trigger Flow -> Next.

In the start element, we have to select the triggering object. In our scenario, Account is a triggering object because it is created when the user creates or updates an account record. For that, in the Configure Trigger, we need to select A record is created or updated.

Then, add a condition: the ‘Account Priority‘ Is Changed ‘True’. Then, I selected  “Actions and Related Records” in the “Optimize the Flow” option.

Salesforce Record Triggered Flow

Next, we need to retrieve all the contacts related to the account. For that, we need to add the Get Records element and enter a Label and API Name.

Then, to filter the contacts, we only want to send emails to those records related to a particular account.

For that, add a condition. Here, I set Account ID (contact lookup field) Equals Account > Account ID. According to this condition, all the contacts related to the account will be stored in this element.

Fetch Records Using Get Record Element in Salesforce Flow

Now, what if any account doesn’t have any related contacts, that means the get record element will be empty. First, we need to check that, and then if the get record contains records, we need to send an email to those contacts.

For that, we need to add a Decision element and provide the OUTCOME ORDER. Here, I provided ‘Not Empty (Get Record)‘ and ‘Empty‘. We can add multiple outcome orders as per our requirement.

Then, for each outcome order, we need to add a condition. For the Not Empty outcome here, I added the following condition:

Get Record (Label) Is Null False. That means if the record element is not empty, then this outcome will be executed.

Otherwise, the Empty outcome will be executed.

Check if Get Records Is Empty in Salesforce Flow

Next, under the ‘Not Empty’ outcome, we need to add a Send Email Action element to send an email after the record is created or updated.

As you add the email action element, you need to provide the Label, and the API Name will automatically populate.

Here you need to select the field values to send an email, such as sender email, subject, body, recipient address, etc.

Send Email Action in Salesforce Flow

Now we are ready to save the flow. For that, click the Save button, provide the flow Label, and the API Name will be automatically populated.

After that, always debug the flow before activating it to ensure that the working flow is correct and that there are no runtime errors.

Click the Debug button, update any record according to the flow entry conditions, and then click the Run button.

How to Run Salesforce Flow

You can see the Debug Details. The Get Record element retrieved the data, and we verified it using a condition. After sending the email, the action was executed.

How to Debug Salesforce Flow

Also, you can see the record we selected to run the flow, which has related contacts.

Contacts Related to Account in Salesforce Flow

In this way, we can check if the record is empty, and if it is not empty, then the flow executes the next actions.

Conclusion

I hope you have an idea of how to check if the Get Records is empty in Salesforce Flow. I have explained by taking a scenario of sending an email to the contacts related to the account.

There, we used a decision element to check whether the get record is empty or not. If not empty, then send an email to the contacts.

You may like to read:

The post Check if Get Records Is Empty in Salesforce Flow appeared first on SalesForce FAQs.


June 26, 2025 at 03:30PM
Click here for more details...

=============================
The original post is available in SalesForce FAQs by Bijay Kumar
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Salesforce