---
title: "Flow assignment element"
url: "https://trailassembly.com/flow-assignment-element/"
topic: "Flow and Automation"
published: "2026-09-20T04:36:47+00:00"
updated: "2026-10-06T13:59:14+00:00"
---

# Flow assignment element

**Assignment sets values on variables in memory and touches the database not at all.** Use **Equals** to overwrite a value, **Add** to append an item to a collection or to sum a number, and a run of Equals rows against a record variable’s fields to build a record you hand to Create Records later. Nearly every problem people hit with this element comes from forgetting that nothing is saved until a Create, Update or Delete element actually runs.

## Assignment is memory, not the database

The element holds a list of rows. Each row names a variable, an operator, and a value. The flow applies them top to bottom in one step, and the debug panel shows the resulting value of each variable after the element finishes.

That is the whole behaviour. No record is written, no field on the triggering record is committed, and no external system hears about it. The one exception is the before-save record-triggered flow, where assigning to a field on `$Record` changes what gets saved because you are editing the record on its way into the database. In an after-save flow the same assignment changes only your in-memory copy, and you need an Update Records element to make it stick.

## The operators, and when each one is right

- **Equals** replaces whatever was there. This is the one you want most of the time.

- **Add** depends on the variable’s type. On a Number it sums. On a Text variable it appends to the end of the existing string. On a collection it adds one item to the end.

- **Subtract** works on numbers and currency.

- **Add at Start** puts an item at the front of a collection instead of the back.

- The remove operators take items back out of a collection by position, by value, or all at once.

A running total is the textbook Add case. Inside a Loop over Opportunity Line Items, one row of `varTotal Add {!currentItem.TotalPrice}` gives you a sum without a single query after the loop starts.

## Adding records to a collection

This is the pattern that makes flows bulk-safe. Inside a Loop, decide whether the current item needs changing. If it does, set the field you want on the loop’s current item variable, then add that item to a record collection variable. After the loop ends, one Update Records element takes the whole collection.

Two rules keep this working:

- The collection variable must be the same object type as the item, and it must have **Allow multiple values** ticked. A single record variable will not accept an Add.

- Each Add stores the values the item holds at that moment. Changing the item variable on the next iteration does not reach back and alter what you already added, which is exactly why collect-then-update is safe.

## Building a record in memory

You can declare a record variable of, say, Case, then use one Assignment to populate it field by field:

```apex
varNewCase.Subject   Equals  "Renewal review: " & {!$Record.Name}
varNewCase.AccountId Equals  {!$Record.Id}
varNewCase.OwnerId   Equals  {!$Record.Owner.ManagerId}
varNewCase.Priority  Equals  "High"
```

Then pass `varNewCase` to a Create Records element set to “use all values from a record variable”. The alternative is to let Create Records build the record from separate field rows. Both work. The variable approach wins when you want to build the record across several branches of a Decision and create it in one place, or when you are adding records to a collection for a single bulk insert.

A record variable you built yourself has no Id until the Create element runs, and it has only the fields you set. It is not a partially loaded record from the database. Do not expect `{!varNewCase.Account.Name}` to resolve, because there is no relationship to walk.

## Where it goes wrong

**Assigning to a null number.** Add against a variable that has never been set gives null, not the value you added. Give numeric variables a default of 0 when you declare them.

**Assigning across types.** A picklist value going into a Text variable is fine. A Text value going into a Number variable is not, and the error message talks about the value rather than the type.

## Frequently asked

**Can Assignment update a field on a record in the database?** Only in a before-save record-triggered flow, where assigning to `$Record` changes what is written. Everywhere else you need Update Records.

**Why does my collection have only one item?** You almost certainly used Equals instead of Add, which replaces the collection with a single-item one on every iteration.

**How do I empty a collection?** Assign it Equals with the value left blank, or use the operator that removes all items. Either resets it before a second pass.

---

Source: https://trailassembly.com/flow-assignment-element/
Trail Assembly — independent Salesforce write-ups.
