Get started now
Guide |

Deluge For Each Loop

(Examples for Zoho CRM and Creator)
Smiling software developer standing in a bright office
Smiling software developer standing in a bright office.
✓2,000+Zoho projects delivered
13+13+ yearsbuilding Zoho systems
●US · Canada · EuropePremium Partner
The deluge for each statement is the loop syntax in Zoho Deluge used to iterate through lists, maps, and record collections in Zoho CRM and Zoho Creator. Small and mid-size businesses use it to update many records, process form submissions, or work through a json formatted string without writing complex code.

Quick answer: what is “deluge for each” and when should you use it?

The deluge for each statement is the loop syntax in Zoho Deluge used to iterate through lists, maps, and record collections in Zoho CRM and Zoho Creator. Small and mid-size businesses use it to update many records, process form submissions, or work through a json formatted string without writing complex code. Amazing Business Results (ABR), working with Zoho since 2013 and a Zoho Premium Partner for 9 years, with 2,000+ Zoho projects, writes custom functions like these for small businesses. Deluge does not support traditional loops like while or classic counter-based for loops, so understanding for each is essential for any serious zoho deluge scripting.

Basics of “deluge for each” in Zoho Deluge

Deluge is Zoho’s scripting language, and the for each loop iterates through list elements across Zoho CRM, Creator, Desk, and other apps. Deluge allows looping through collection variables only, using for each and for each index as the primary tools. You do not need to declare the loop variable before using it. Deluge has dynamic data types, so for each element in a collection, developers can execute specific code multiple times without type declarations.

numbers = {10,20,30};
for each n in numbers
{
    info n;
}

This prints each number in order. These rules apply the same way in any zoho deluge environment. Connect this to common tasks like walking through a list of invoice IDs each week or processing contact entries.

Loop patterns: lists, maps, JSON, and fixed number iterations

Below we discuss practical patterns for looping over different data structures. Deluge can loop through collection variables using for each in several ways.

Iterating over a list

product_list = {"SKU-1001","SKU-1002","SKU-1003"};
for each sku in product_list
{
    info "Processing: " + sku;
}

Each item in the list variable is processed once per iteration. Use this to generate renewal reminders, build a string from elements, or populate a report from an array of values.

Iterating over a map’s keys and values

Deluge iterates over a map by using its keys. A map holds key-value pairs, and you fetch the collection of keys to loop through them.

employee_salary = Map();
employee_salary.put("Alice",50000);
employee_salary.put("Bob",60000);

for each empName in employee_salary.keys()
{
    sal = employee_salary.get(empName);
    info empName + " earns " + sal.toString();
}

This is useful for configuration maps, tax rate tables, or status label lookups in a custom function where entries equal specific business rules.

Looping over a JSON formatted string

You cannot loop directly over raw json strings. Convert them first using toJSONList(). Deluge allows iterating through API responses by converting JSON strings to a list.

json_text = "[{\"Name\":\"Alice\"},{\"Name\":\"Bob\"}]";
json_list = json_text.toJSONList();

for each person in json_list
{
    info person.get("Name");
}

Each element is treated like a map. Use this to parse webhook payloads from an external url, API response data, or settings stored as JSON in Creator.

Using “for each index” to access positions

Deluge does not automatically track a numeric index in loops. To track the current item position in a loop, use the for each index variation.

colors = {"red","green","blue"};
for each index i in colors
{
    info "(" + i.toString() + ") " + colors.get(i);
}

This outputs the index alongside each value. It is helpful when syncing two parallel lists or when the list size matters for a page layout.

Simulating a fixed number loop

Deluge has no counting loop such as “repeat 5 times”. To run a block a fixed number of times, loop over a list that has that many items. This works well for small counts.

runs = {1,2,3,4,5};
for each run in runs
{
    info "Run #" + run.toString();
}

This runs the block five times. For large counts, redesign the logic instead, because long loops risk hitting platform limits.

Using “deluge for each” in Zoho CRM and Creator custom functions

This section covers real-world patterns that zoho developers and technical staff at small businesses can adapt directly.

Looping over related records from zoho.crm.getRelatedRecords

In Zoho CRM you often fetch related records and then loop to perform a task on each one. Conditions can be applied within for each loops to filter outputs, and you can summarize or transform data within for each loops by aggregating values or creating new lists.

// accountId is an argument of the custom function
deals = zoho.crm.getRelatedRecords("Deals","Accounts",accountId);

total_amount = 0.0;
for each d in deals
{
    if(d.get("Stage") == "Closed Won")
    {
        total_amount = total_amount + ifnull(d.get("Amount"),0.0);
    }
}
info "Total Closed Won amount: " + total_amount.toString();

The for each loop drives the calculation by checking each deal’s Stage field. The function parameters come from the workflow trigger. If a record is deleted between the fetch and the update, add a null check to avoid a silent error.

Looping over search results from zoho.crm.searchRecords

Run the search once, then iterate the returned collection variable with for each. This avoids repeated API calls, which would be a bad practice mentioned often in Zoho documentation.

// email is an argument of the custom function
criteria = "(Email:equals:" + email + ")";
leads = zoho.crm.searchRecords("Leads",criteria);

for each lead in leads
{
    update_map = Map();
    update_map.put("Lead_Source","Web form");
    update_resp = zoho.crm.updateRecord("Leads",lead.get("id").toLong(),update_map);
}

Each lead is updated inside the loop. This pattern is common when normal workflow rules cannot solve the requirement, regardless of region or Zoho edition.

Iterating through records in a Zoho Creator form

Deluge can process lists of records directly fetched from Zoho Creator forms. The collection variable holds all matching records, and the loop variable takes each one in turn.

employee_list = Employees[Status == "Active"];
for each emp in employee_list
{
    sendmail
    [
        from : zoho.adminuserid
        to : emp.Email
        subject : "Policy update"
        message : "Hi " + emp.Name + ", please review the new policy."
    ];
}

This sends a date-stamped policy update to all active employees. The for each record tool in Creator supports sorting and range, but this article focuses on script-style code inside custom functions.

Performance limits, errors, and safer “deluge for each” design

Loops in Zoho Deluge must respect platform limits. API rate limits and execution limits exist when using Zoho Deluge scripts, including statement counts and execution time caps. Nesting loops across multiple layers or calling external APIs inside large for each loops can quickly produce an error occurred response. Deluge does not support breaking or continuing loops directly, so plan your logic to avoid unnecessary iterations.

Avoid calling APIs inside large loops

Calling zoho.crm.getRecordById on every iteration when you need to batch process hundreds of items is incredibly inefficient. Best practices recommend collecting IDs for bulk processing outside of loops. Fetch all needed data before the loop, or split the work into scheduled functions. With luck and good planning, a single fetch call before the loop replaces hundreds of calls inside it.

Common errors in for each loops and how to prevent them

Avoid modifying the collection while iterating to prevent runtime errors. Deluge throws errors for infinite loops during list additions, so never keep adding elements to the same list you are looping over. Also watch for mis-typed form or module names and missing field values.

try
{
    for each item in inputList
    {
        // process item
    }
}
catch (e)
{
    info "Error occurred in loop: " + e.toString();
}

This try-catch pattern logs a helpful error message instead of stopping the whole script silently. Using ifnull and isNull checks inside the loop makes debugging faster. Add a comment in your code near each field access so a future user or developer reviewing a previous version of the file can follow the logic.

When to use a custom function instead of a workflow only

Complex multi-record operations almost always require a custom function with one or more for each loops rather than a point-and-click workflow. Example scenario: once a Deal is marked Closed Won, a function loops through related Contacts to populate a “Last Purchase Date” and send follow-up emails. Deluge also limits how deeply a function can call itself, so keep that in mind if your solution uses recursion. ABR, a Zoho Premium Partner for 9 years with 190+ five-star reviews on Zoho and Google, can review your requirements and give a price after seeing the full scope of the for each logic and API usage involved.

Pattern / use / example table

Here is a quick-reference table for deluge for each patterns.

Pattern

Typical Use

Short Example

for each item in listVar

Process a static or computed list of values

for each sku in sku_list { /* logic */ }

for each key in map.keySet()

Read or update values in a configuration or lookup map

for each k in config.keySet() { v = config.get(k); }

for each rec in recordCollection

Handle Zoho CRM or Creator records returned by a fetch or search

for each deal in deals { /* update */ }

for each index i in listVar

Need both index and value, or sync parallel lists

for each index i in items { info items.get(i); }

Loop over JSON list

Parse API or webhook data stored as JSON text

for each row in json_text.toJSONList() { /* use row */ }

Frequently Asked Questions about “deluge for each”

Below are common questions about deluge for each loops and how they apply to Zoho CRM and Creator automation.

What is “deluge for each” and how is it different from a normal for loop?

Deluge for each is the only loop syntax available in Zoho Deluge. Unlike a classic counter-based for loop, it iterates directly over a collection variable such as a list, map, or set of records. This design fits the ability of non-programmer users to create automation in Zoho apps without managing counters or worrying about an end condition that could cause an infinite loop.

Can I use “deluge for each” to loop over Zoho CRM records?

Yes. You call zoho.crm.getRelatedRecords, zoho.crm.searchRecords, or a similar function to fetch a list of records into a collection. Then use for each to read or update fields on each record. The support for this pattern is built into every Zoho CRM edition that allows custom functions.

How do I loop over a JSON formatted string in Zoho Deluge?

Convert the raw JSON text to a list using toJSONList(), then use a standard for each loop. Each element in the resulting list behaves like a map, so you can call .get(“FieldName”) to access values. This is how you post or consume data from third-party APIs.

What should I do if an error occurred inside my for each loop?

Wrap the loop body in a try-catch block and log the error with info. Use ifnull to guard against null field values. Reduce API calls inside the loop to stay within limits. These steps make debugging straightforward and prevent one bad record from stopping the entire script.

When does it make sense to hire help for Zoho Deluge custom functions?

Once your needs involve nested loops, heavy JSON parsing, or respect for CRM API limits, working with a Zoho Premium Partner like Amazing Business Results (ABR) is often more efficient. ABR has handled over two thousand Zoho projects and can scope and price a solution based on the exact for each logic, batch processing, and integration requirements your business needs.

Work with Amazing Business Results

We build custom Zoho systems around how your business actually runs. We extract your real requirements and translate them into Zoho configurations that fit your business, plus the development and training to make sure your team uses them correctly. As the most reviewed Zoho Partner in the world, with 2,000+ completed projects since 2013, we treat the root cause, not the symptom.

More from this section

Recent guides filed under the same category.