Every 10 minutes
Turn enquiry emails into Salesforce leads
Emails you label Leads in Gmail become Salesforce leads with the contact details filled in, and are moved out of the way.
- Runs
- Every 10 minutes
- Apps
- Gmail, Salesforce
- AI
- Yes, uses the built-in AI allowance
- Access
- gmail.modify; api
Send this to your assistant
Create a ClickRuntime automation: every 10 minutes, read new emails labelled Leads, pull out the sender's name, company, phone and what they need, create a Salesforce lead if there isn't one, and move the email to Leads/Done.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A lot of business still starts with an email: a forwarded introduction, a reply to a newsletter, a question sent to the sales inbox. Each one has to be read, the details copied into Salesforce, and the email filed. On a busy week, half of them don't make it into the CRM.
With this automation you only label the email. Every ten minutes it reads new labelled messages, pulls out the contact details and what the person needs, creates a Salesforce lead if they're new, and files the email under Leads/Done.
What you get out of it
One label instead of ten fields
Labelling an email, by hand or with a Gmail filter, is all it takes to get the lead into Salesforce.
Details pulled from the text
Name, company and phone are read from the email and its signature, which saves typing.
No duplicate leads
If a lead with that email exists, nothing new is created.
A tidy inbox
Processed emails move to Leads/Done, so the Leads label only ever shows what's waiting.
How it works
What happens, step by step
Every 10 minutes the automation checks Gmail for emails with the Leads label.
AI reads each email and pulls out the sender's name, email, company, phone and what they need.
It checks Salesforce for an existing lead with that email and creates one only if there isn't.
The email is moved from Leads to Leads/Done so it's never processed twice.
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
Build your own
Need it to work differently?
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
- Act only on the items that match your own rules, and skip the rest
- 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
import base64
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_trigger, report_fetched, credentials, http, ai
API = "https://yourcompany.my.salesforce.com/services/data/v61.0"
SCHEMA = {"type": "object", "properties": {k: {"type": "string"} for k in
["first_name", "last_name", "email", "company", "phone", "need"]}, "required": ["last_name", "email", "company"]}
@on_trigger
def run(event):
gmail = build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False).users()
labels = {l["name"]: l["id"] for l in gmail.labels().list(userId="me").execute()["labels"]}
msgs = gmail.messages().list(userId="me", labelIds=[labels["Leads"]], maxResults=20).execute().get("messages", [])
report_fetched(len(msgs))
if not msgs:
return {"summary": "No new lead emails"}
headers, created = {"Authorization": f"Bearer {credentials.connection('salesforce', 'work')}"}, 0
for m in msgs:
full = gmail.messages().get(userId="me", id=m["id"], format="full").execute()
body = next((base64.urlsafe_b64decode(p["body"]["data"]).decode(errors="ignore") for p in full["payload"].get("parts") or [full["payload"]]
if p.get("mimeType") == "text/plain" and p["body"].get("data")), full["snippet"])
d = ai.generate("Pull the sender's contact details and what they need from this enquiry email:\n" + body[:3000], json_schema=SCHEMA, max_output_tokens=200).json
email = d["email"].replace("'", "")
if not http.get(f"{API}/query", headers=headers, params={"q": f"SELECT Id FROM Lead WHERE Email = '{email}' LIMIT 1"}).json()["records"]:
http.post(f"{API}/sobjects/Lead", headers=headers, json={"FirstName": d.get("first_name"), "LastName": d["last_name"], "Email": email,
"Company": d["company"] or "Unknown", "Phone": d.get("phone"), "LeadSource": "Email", "Description": d.get("need")}).raise_for_status()
created += 1
gmail.messages().modify(userId="me", id=m["id"], body={"removeLabelIds": [labels["Leads"]], "addLabelIds": [labels["Leads/Done"]]}).execute()
return {"emails": len(msgs), "created": created}FAQ
Common questions
Do I need to create the labels?
Can emails be labelled automatically?
What if the email doesn't include a company?
What permissions does it need?
Does it need AI?
How many runs does it use?
Can I change how it works?
Related
You might also like
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.
See how it worksGet a monthly strategy brief for your key accounts
Each month you get an email with upsell gaps, competitor risks and a suggested next move for each of your top accounts.
See how it worksGet a weekly email of your team's Salesforce activity
Every Monday you get an email showing each rep's tasks, meetings, deals moved and revenue won last week, with short coaching notes.
See how it worksKeep exploring
Set up “Turn enquiry emails into Salesforce leads” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.