Skip to content

Weekly

Get a weekly email of customers at risk of leaving

Each week you get an email listing customers whose health looks poor, with a score, the reason and how it changed since last week.

Runs
Weekly
Apps
Gmail, Salesforce
AI
Yes, uses the built-in AI allowance
Access
api; gmail.send

Send this to your assistant

Create a ClickRuntime automation: every week, score each customer's health from Salesforce activity, renewals and support cases, and email me the ones at risk with the reason.

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

The head of customer success at a growing SaaS company has a hundred customers and a team of three. Most weeks there's no time to check every account, so the ones in trouble surface when they ask to cancel.

This automation looks at every customer in Salesforce each week, gives them a health score from their activity, upcoming renewal and recent support cases, and emails you the ones scoring low, with why and how the score has changed.

What you get out of it

  • Every customer checked, every week

    Accounts nobody has looked at in a while get the same attention as the noisy ones.

  • Trend, not just a number

    Each at-risk account shows last week's score too, so you can see who is getting worse.

  • A reason to start the conversation

    The one-line reason, such as several urgent cases in the last month, tells your team what to raise.

  • Quiet when things are fine

    If no account scores low, no email is sent.

How it works

What happens, step by step

  1. Every week the automation reads your customer accounts from Salesforce with their last activity, renewal date and recent cases.

  2. AI gives each customer a health score from 1 to 10 with a reason.

  3. Scores are compared with last week's to show the trend.

  4. Customers scoring 4 or below are emailed to you from your Gmail account.

Before it runs live

  • Connect Google through your own Google app (a one-time, 10-minute setup), so it works with your own Gmail
  • Connect Salesforce

What you get

RunsWeekly
Get a weekly email of customers at risk of leavingtoday, 9:00Succeeded
Email · Customer healthLitware Inc: 3/10 (was 6) - three high-priority cases this month and renewal in 45 days.

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
  • Change what the AI looks for, or how it writes the result
  • Add another app, for example also send it to Slack
  • Combine it with other Gmail and Salesforce 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.
customer_health_churn_risk_email.pyexample
import base64
from email.message import EmailMessage
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_trigger, credentials, http, state, ai
ME, INSTANCE = "me@northwind.example", "https://yourcompany.my.salesforce.com"
SCHEMA = {"type": "object", "properties": {"accounts": {"type": "array", "items": {"type": "object", "properties": {
    "n": {"type": "integer"}, "health": {"type": "integer"}, "reason": {"type": "string"}}}}}, "required": ["accounts"]}
def send(subject, body):
    msg = EmailMessage()
    msg["To"], msg["Subject"] = ME, subject
    msg.set_content(body)
    gmail = build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False)
    gmail.users().messages().send(userId="me", body={"raw": base64.urlsafe_b64encode(msg.as_bytes()).decode()}).execute()
@on_trigger
def run(event):
    headers = {"Authorization": f"Bearer {credentials.connection('salesforce', 'work')}"}
    accts = http.get(f"{INSTANCE}/services/data/v61.0/query", headers=headers, params={"q": "SELECT Id, Name, LastActivityDate, Renewal_Date__c, "
            "(SELECT Priority FROM Cases WHERE CreatedDate = LAST_N_DAYS:90) FROM Account WHERE Type = 'Customer' LIMIT 80"}).json()["records"]
    lines = [f"{i + 1}. {a['Name']} | last activity {a['LastActivityDate']} | renews {a['Renewal_Date__c']} | "
             f"cases 90d: {[c['Priority'] for c in (a.get('Cases') or {}).get('records', [])]}" for i, a in enumerate(accts)]
    scored = ai.generate("Score each customer's health 1 (about to churn) to 10 (healthy) with a one-line reason.\n" + "\n".join(lines),
                         json_schema=SCHEMA, max_output_tokens=1800).json["accounts"]
    before = state.get("health") or {}
    risky = [f"{accts[s['n'] - 1]['Name']}: {s['health']}/10 (last week {before.get(accts[s['n'] - 1]['Id'], 'n/a')}) - {s['reason']}\n"
             f"{INSTANCE}/{accts[s['n'] - 1]['Id']}" for s in scored if s["health"] <= 4]
    state.set("health", {accts[s["n"] - 1]["Id"]: s["health"] for s in scored})
    if risky:
        send(f"{len(risky)} customers at risk this week", "\n\n".join(risky))
    return {"scored": len(scored), "at_risk": len(risky)}

FAQ

Common questions

Which customers are scored?
Accounts with the type Customer, up to 80 per run. Change the filter to match how your org marks customers.
What counts as at risk?
A health score of 4 or below out of 10. You can raise or lower the cutoff.
Can it include product usage?
Yes, if usage is stored in Salesforce, for example as a field on the account. Ask your AI assistant to add it to what the score looks at.
What permissions does it need?
api; gmail.send. Nothing else in your accounts is used.
Does it need AI?
Yes. It uses ClickRuntime's built-in AI, so you don't need an OpenAI or Anthropic key. Every plan includes a monthly AI allowance.
How many runs does it use?
One run each time it runs (weekly). 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 “Get a weekly email of customers at risk of leaving” from your assistant

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