Use Case #3: Rename an Uploaded File

Rename a file after it’s been uploaded. This post is part of the Uploading and Working with Files in Flow mini series.


  • Install/setup flow package
  • Flow: E01_003_RenameUploadedFile
  • Standard File Upload flow screen component (included in the flow)
  • Case object – need at least one case record in your org

Video Tutorial (1 min)

What’s Happening in the Flow:

  1. This flow is just like the “Upload a Single File” sample flow, but with a twist. I’ll just cover the twist.
  2. “Loop on Content Document” loop (I can tell you weren’t expecting the twist to be literal): After uploading the file on the first screen, we enter a loop on the Content Document Ids that are an output of the File Upload component. Even though the component is set to allow only a single file upload, it could be used multiple times, and so the Content Document Id(s) and the Content Version Id(s) are output in collection variables (what old developers might call arrays)… so the loop allows us to evaluate each Content Document Id in the collection separately (all one of them).
  3. “Update Content Document” query: Renaming the uploaded Content Document is the only thing we need to do in the loop, so let’s get right to it.
    1. We use the current loop item’s value (a single ContentDocument Id) to update the Title field to “My Coconut-Filled File” (I told you to be careful with this sampler).
    2. “My Coconut-Filled File” was just a value I hard-coded into the Update element, but I could have dynamically set Title using a text variable, a constant, a formula for today’s date, maybe a Text field on the previous screen where the user could provide a new title… essentially any value available to the flow, so the possibilities are endless.
    3. For Your Awareness: You typically should avoid DML statements (Gets, Creates, Updates, Deletes) inside a loop, because you can easily hit limits and cause user-facing errors. This is especially risky when you don’t know how many items you’re looping on. However, this our loop will only ever have a collection of one record, we’re safe doing it this way.
  4. That’s it! That one little Loop and an Update renamed our uploaded file.

Please review Some Limits for caveats related to this particular use case.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: