Omnistudio : Using SetValues in Integration Procedures: Beware of Heap Size!
Introduction
When building solutions with Salesforce OmniStudio’s Integration Procedures, the SetValues
element is a handy tool for developers. It lets you assign data to variables or JSON nodes, making it super versatile and powerful. However, using SetValues
too often and without control can quickly hit a critical Salesforce governor limit: heap size.
In this article, we’ll explore what heap size is, how SetValues
affects it, and share some best practices to help you avoid common issues when working with large datasets.
What is Heap Size and Why Does It Matter?
Heap size is the amount of memory used to store objects and data structures while a transaction runs in Salesforce. When your Integration Procedure runs, it keeps variables, JSON nodes, and other temporary data in memory, which uses up heap space.
Salesforce sets heap size limits to make sure no single transaction uses too many system resources in a shared environment. The current limits are:
6MB for synchronous transactions.
12MB for asynchronous transactions.
If you go over these limits, you'll get a "Heap Size Too Large" error, and your Integration Procedure will fail. So, it's really important to understand and manage heap size to build scalable and efficient solutions.
The Role of SetValues in Integration Procedures
In OmniStudio, Integration Procedures offer an easy way to manage API calls or server calls, transform data, and handle variables. SetValues
is a popular tool within these procedures to:
Assign values to variables.
Modify JSON nodes.
Prepare data for external calls or for use in UI components.
SetValues
is quite flexible and lets you work with different types of data. However, each SetValues
step creates or updates objects in memory. The more you use SetValues
, the more data gets stored, which can quickly add up to a large heap size.
For instance, if you're setting large JSON structures or multiple variables, each SetValues
instance keeps the data in memory until the procedure finishes.
How SetValues Contributes to Heap Size Issues
Each SetValues
step creates a new variable or changes an existing one, and this data stays in memory. If you're working with large datasets or multiple JSON nodes, your heap size can grow quickly. When these objects get big enough, you might hit the heap size limits and get an error.
This becomes a bigger issue when:
The
SetValues
steps hold large JSON structures.Many
SetValues
steps are used within a single Integration Procedure.
Best Practices for Managing Heap Size in SetValues
Use SetValues carefully
Do not use SetValues unnecessarily. Always ensure that each SetValues step you include in your Integration Procedure is absolutely necessary for the task at hand. Carefully review your logic to determine if you can achieve the same result with fewer SetValues steps or by using alternative methods.
Limit the Size of the Data Assigned
Try not to store overly large objects or datasets in memory. Instead, break down big objects and keep only the information you need at the moment. If you can, work with smaller chunks of data rather than loading everything at once.
For example, if you get a large JSON object from an API, just pull out the fields you need for the current task, instead of storing the whole object.
Use Conditional SetValues Logic
Only set values when they are truly necessary. By introducing conditional logic, you can prevent unnecessary data assignments and reduce memory usage.
Offload Complex Data Transformations to DataRaptors
When you need to transform or map data, consider using DataRaptors for the heavy lifting. DataRaptors are great at transforming and mapping data, and they can handle complex tasks more efficiently without using up too much heap space like Integration Procedures can.
Use
SetValues
sparingly for simple assignments and let DataRaptors take care of the heavy transformations outside the Integration Procedure whenever you can.
Now let's look at an example in hand:
Practical Example
I tried with a simple example, with these steps:
Create an Integration procedure.
Do a callout to fetch 5000 data points.
Add a setValue element to assign these 5000 data points to a new variable.
Add a response action element to return the data from Integration Procedure.
When IP is executed it throws
But if I deactivate it returns proper response.
Conclusion
The SetValues
element is a powerful tool in OmniStudio Integration Procedures, but it must be used with caution. Every SetValues
step holds data in memory, contributing to heap size. Without careful management, excessive or inefficient use of SetValues
can lead to heap size overages, performance issues, and even transaction failures.
Subscribe to my newsletter
Read articles from Nagendra Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Nagendra Singh
Nagendra Singh
Allow me to introduce myself, the Salesforce Technical Architect who's got more game than a seasoned poker player! With a decade of experience under my belt, I've been designing tailor-made solutions that drive business growth like a rocket launching into space. 🚀 When it comes to programming languages like JavaScript and Python, I wield them like a skilled chef with a set of knives, slicing and dicing my way to seamless integrations and robust applications. 🍽️ As a fervent advocate for automation, I've whipped up efficient DevOps pipelines with Jenkins, and even crafted a deployment app using AngularJS that's as sleek as a luxury sports car. 🏎️ Not one to rest on my laurels, I keep my finger on the pulse of industry trends, share my wisdom on technical blogs, and actively participate in the Salesforce Stackexchange community. In fact, this year I've climbed my way to the top 3% of the rankings! 🧗♂️ So, here's to me – your humor-loving, ultra-professional Salesforce Technical Architect! 🥳