Flow Apex Action: Create ContentVersion/Files

Hi! 🙂

We cannot create Files(ContentVersion) using the Create Records element in Flows. And the reason is flow doesn’t support Blob data type in flow variables.

Are you wondering why do we need this since we can simply upload files using the standard FileUpload component? Well, what if wanted to create a Note? It can be also useful where you’re receiving blob/base64 data for images through APIs.

So, how does it work?

It’s quite simple. The action takes some inputs and returns the ContentDocument ID of the inserted file.

Parameter Use for Input Use for Output Description
File Data String input that’ll be stored as VersionData. For images, the string input should be base64 encoded string.
File Extenstion Type of the file. For notes, it should be ‘SNOTE’.
File Title Title of the file.
Related Record Id ID of the record where the file should be added.
ContentDocument ID ContentDocument ID of the created file(ContentVersion).

You can find the link for the unmanaged package and source code here:
https://github.com/forcePanda/Flow-Repo/tree/master/Apex%20Actions/CreateContentVersion(Files)

Demo

Hope you found this one useful! Catch you in the next one! ✌
Thank you for being an awesome reader! Subscribe to this blog for receiving all the latest updates straight to your inbox.

6 thoughts on “Flow Apex Action: Create ContentVersion/Files

  1. Hi, I’m trying to make a copy of a Content Version within Saleforce. Within flow, I get the VersionData from the ContentVersion and feed this into your Action. However, the flow fails with this message:

    Error element null (null).
    Value of class core.filemanager.FileBlobValue is not a ValueType: STRING

    Like

    • If you’re trying to make a copy of content version file, then you can create another content version type record variable and set the fields from the original record variable. Then use Create Record element with cloned variable.

      Like

  2. Thank you for sharing this, very useful.
    In my Flow I have a Rich Text input element that I would lke to be the ‘File Data’. When the Note is created the Rich Text is presented as html tags and not as formatting. Is there a way that the formatting can be retained on the created Note?

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.