Skip to content

On a schedule

Move old Salesforce files to S3 and report in Slack

Every week, Salesforce files older than a year are moved to your S3 bucket to free up storage, and Slack reports how many files and megabytes were archived.

Runs
On a schedule
Apps
AWS, Slack
AI
Not needed
Access
s3:PutObject; chat:write

Send this to your assistant

Create a ClickRuntime automation: every Sunday, move Salesforce files older than a year into S3, delete them from Salesforce once copied, and post how many files and MB were archived to #ops.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

Salesforce file storage is expensive, and years of attachments, signed contracts and old proposals fill it up. Buying more storage costs far more than keeping the same files in S3, but moving them by hand is a project nobody wants.

A weekly job that moves anything older than a year keeps Salesforce under its storage limit while the files stay available in your own bucket.

What you get out of it

  • Lower storage costs

    S3 storage costs a fraction of extra Salesforce file storage.

  • Stay under your limit

    A steady weekly clear-out avoids hitting the storage cap at a bad moment.

  • Nothing is lost

    Each file is copied and checked in S3 before it's removed from Salesforce.

  • A visible record

    The Slack report shows how much was moved each week.

How it works

What happens, step by step

  1. Every Sunday, ClickRuntime asks Salesforce for files last changed more than a year ago.

  2. It downloads each one and saves it to your S3 bucket.

  3. Once a file is safely in S3, it's deleted from Salesforce.

  4. It posts the number of files and megabytes archived to #ops in Slack.

Before it runs live

  • Connect AWS
  • Connect Slack, then invite the app to the channel (type /invite @ClickRuntime there)

What you get

RunsOn a schedule
Move old Salesforce files to S3 and report in Slacktoday, 9:00Succeeded
Slack · #opsArchived 184 Salesforce files (912.4 MB) to s3://northwind-files/salesforce-archive/

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Run it at a different time, more or less often, or only on weekdays
  • Add an AI step, for example to summarize, sort or draft a reply
  • Add another app, for example also send it to Google Sheets
  • Combine it with other AWS and Slack steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
archive_old_files_to_s3_and_report_in_slack.pyexample
import boto3
from clickruntime import on_trigger, credentials, http, notify

SF = "https://northwind.my.salesforce.com/services/data/v61.0"
REGION, BUCKET = "us-east-1", "northwind-files"

def aws(service):
    return boto3.client(service, region_name=REGION, aws_access_key_id=credentials.secret("AWS_ACCESS_KEY_ID"),
                        aws_secret_access_key=credentials.secret("AWS_SECRET_ACCESS_KEY"))

@on_trigger
def run(event):
    sf = {"Authorization": "Bearer " + credentials.connection("salesforce", "work")}
    q = "SELECT Id, ContentDocumentId, Title, FileExtension, ContentSize FROM ContentVersion WHERE IsLatest = true AND LastModifiedDate < LAST_N_DAYS:365 LIMIT 200"
    files = http.get(f"{SF}/query", headers=sf, params={"q": q}).json()["records"]
    s3, moved, size = aws("s3"), 0, 0
    for f in files:
        data = http.get(f"{SF}/sobjects/ContentVersion/{f['Id']}/VersionData", headers=sf, timeout=60).content
        s3.put_object(Bucket=BUCKET, Key=f"salesforce-archive/{f['ContentDocumentId']}-{f['Title']}.{f['FileExtension']}", Body=data)
        http.delete(f"{SF}/sobjects/ContentDocument/{f['ContentDocumentId']}", headers=sf).raise_for_status()
        moved, size = moved + 1, size + f["ContentSize"]
    notify.slack(f"Archived {moved} Salesforce files ({size / 1e6:,.1f} MB) to s3://{BUCKET}/salesforce-archive/", channel="#ops")
    return {"files": moved, "mb": round(size / 1e6, 1)}

FAQ

Common questions

Can people still find archived files?
They're in S3, organised by year and file name. Ask for the S3 path to be written to the related Salesforce record if people need to find them from there.
Is anything deleted before it's safely copied?
No. A file is deleted from Salesforce only after the upload to S3 succeeds.
Can I exclude certain files?
Yes, for example by file type or by the record they're attached to.
What permissions does it need?
s3:PutObject; chat:write. Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run each time it runs (on a schedule). Checks that find nothing to do and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Move old Salesforce files to S3 and report in Slack” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.