Count files added to a Salesforce record

I got a question earlier today about how can we check if a user has added a file to a Salesforce record. While this solution is not a perfect result because we don’t know the contents of the file to see if they uploaded the correct one, we can check if there are any files related to the record in question.

Files in Salesforce are stored as Content Document records and there are several objects that allow them to be stored, related to records and have version control. The object that we are interested in is the Content Document Link so we can check if there are any files related to our record.

We will create a new field on the Account record that contains a count of related files. We will then use a Record Triggered flow to update this field. If you want to count files on another object, just create this field on your desired object and change the object in the Choose Object screen below.

Once we have this counter on the record, we can use a validation rule to check if it is greater than zero – to indicate if a file has been uploaded or not.


Next, we will create a record triggered flow that will update that field.

It’s a pretty simple flow with only a few elements. When completed, it wil look like this:

On with the flow !

First, select a Record-Triggered Flow:

Perform this action when a record is created or updated and after the record is saved.

Correction: Change to Trigger the Flow When: A record is updated (in the screen below).

Select the Account object and always update it.


Get all Content Document Links that have a link to our record.


Set our new counter field to equal the count of records that we found from our get records.


Finally, update the record.


Test and see if it works!
Here is the counter value:

Here are the 3 files, success!

Remember you need to update the Account record for this trigger to run and update the counter.

Want to learn more about Flow?

Check out our Learning Salesforce Flow course at CertifyCRM.com.

Leave a Reply

Your email address will not be published. Required fields are marked *