Sarah, a top-performing sales director at a rapidly growing tech firm, started every morning the aame way: diving headfirst into a sea of Salesforce reports. She’d click through dashboards, filter lists, and open individual opportunity records, trying to piece together the narrative of her team’s pipeline. Which deals were progressing? Which were stalled? Who needed coaching? The data was all there, but it was static, fragmented, and silent. It couldn’t convey the urgency of a deal moving to the final stage or the subtle context behind a sudden change in closing date. Her days were a blur of manual data-sifting, leaving her less time for what truly mattered: strategizing with her team and closing major accounts. Sarah’s challenge is one that countless sales leaders face: the gap between data-rich CRMs and actionable, engaging intelligence.
In today’s fast-paced sales environment, the latency between an event occurring in your CRM and your ability to act on it can be the difference between winning and losing a deal. Traditional email notifications and dashboard alerts are easily lost in the digital noise. What if, instead of another line item in a report, you could receive an instant, personalized video summary the moment a high-value opportunity moves to a new stage? Imagine a custom AI avatar, speaking with a natural, human-like voice, delivering the key details directly to you: “Hi Sarah, just a quick update. Mark’s opportunity for ‘Project Titan’ just entered the ‘Negotiation’ stage, with a value of $250,000. Next steps are to finalize the MSA by Friday.” This isn’t science fiction; it’s a practical application of generative AI that can transform your sales operations.
This article provides a complete technical walkthrough for building such a system. We will show you how to connect the world’s leading CRM, Salesforce, with two powerful AI platforms: ElevenLabs for dynamic, studio-quality text-to-speech, and HeyGen for scalable, personalized AI video creation. We’ll lay out the architectural blueprint, from configuring triggers within Salesforce to orchestrating the API calls that generate and deliver your final video update. You will learn how to turn your static CRM data into a dynamic, event-driven communication channel that keeps your entire sales organization informed, aligned, and ready to act. Get ready to bridge the gap between data and action, and bring your sales pipeline to life.
The Architectural Blueprint: Connecting Salesforce, ElevenLabs, and HeyGen
To build a robust and scalable automation pipeline, we can’t simply connect our platforms directly. We need a central orchestrator—a middleware component—to manage the workflow, handle authentication securely, and process the data at each stage. This architecture ensures that each part of the system is decoupled, making it easier to manage, update, and troubleshoot.
Core Components of the Automation Pipeline
Our system will consist of four main components working in concert:
- Salesforce: The source of truth for our sales data. We will configure it to fire an event whenever a specific change occurs on an Opportunity record, such as a stage update.
- Middleware (e.g., AWS Lambda, Google Cloud Function): This is the brains of the operation. It’s a serverless function that listens for events from Salesforce, processes the data, and orchestrates the calls to the AI APIs.
- ElevenLabs: This platform will take a dynamically generated text script from our middleware and convert it into a natural, high-quality audio file.
- HeyGen: This AI video platform will take the audio file from ElevenLabs, combine it with a pre-selected avatar and template, and generate a personalized video update.
The workflow is sequential: A Salesforce event triggers the middleware, which prepares a script and sends it to ElevenLabs. The middleware then takes the resulting audio and sends it, along with other parameters, to HeyGen to create the video. Finally, the middleware distributes the finished video.
Why a Middleware Approach is Essential
A middleware function is critical for several reasons. First, it provides a secure environment to store and manage sensitive API keys for ElevenLabs and HeyGen, preventing them from being exposed in a front-end system or within Salesforce. Second, it orchestrates the asynchronous nature of the AI services. Video rendering, for example, is not instantaneous. The middleware can initiate the video generation process with HeyGen and then use a webhook or polling mechanism to wait for completion before proceeding to the final notification step. This prevents workflow failures and improves reliability.
Security and Authentication
To ensure the system is secure, we’ll use best practices for authentication at each step. For Salesforce, you can create a Connected App that allows the middleware to authenticate securely using the OAuth 2.0 protocol. This is far more secure than storing a username and password. For the affiliate services, API keys for ElevenLabs and HeyGen should be stored in a dedicated secrets management service like AWS Secrets Manager or Google Secret Manager and retrieved by the middleware only at runtime.
Step 1: Configuring Salesforce to Trigger the Workflow
The first step is to make Salesforce proactively communicate updates to our middleware. The most modern and scalable method for this is using Platform Events, which are part of Salesforce’s enterprise messaging platform.
Setting Up a Platform Event in Salesforce
First, navigate to Setup > Integrations > Platform Events in Salesforce and create a new Platform Event. Let’s call it Opportunity_Update__e
. Define custom fields on this event to hold the data you want to pass, such as:
OpportunityName__c
(Text)AccountName__c
(Text)StageName__c
(Text)Amount__c
(Currency)OwnerName__c
(Text)NextSteps__c
(Long Text Area)
These fields will serve as the payload that our middleware consumes.
Creating an Apex Trigger to Publish the Event
Next, we need to create an Apex trigger that fires when an Opportunity is updated. This trigger will check if the StageName
has changed and, if so, populate and publish our new Platform Event.
Navigate to Setup > Object Manager > Opportunity > Triggers and create a new trigger with the following logic:
trigger OpportunityStageChangeTrigger on Opportunity (after update) {
List<Opportunity_Update__e> eventsToPublish = new List<Opportunity_Update__e>();
for (Opportunity opp : Trigger.new) {
// Check if the stage has changed
Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
if (opp.StageName != oldOpp.StageName) {
// Create the Platform Event instance
Opportunity_Update__e event = new Opportunity_Update__e(
OpportunityName__c = opp.Name,
AccountName__c = opp.Account.Name,
StageName__c = opp.StageName,
Amount__c = opp.Amount,
OwnerName__c = opp.Owner.Name,
NextSteps__c = opp.NextStep
);
eventsToPublish.add(event);
}
}
// Publish the events
if (!eventsToPublish.isEmpty()) {
List<Database.SaveResult> results = EventBus.publish(eventsToPublish);
}
}
This code efficiently checks for stage changes on updated opportunities and publishes a new event with all the relevant context for each one.
Step 2: Generating Dynamic Voiceovers with ElevenLabs
Once our middleware receives the Opportunity_Update__e
event from Salesforce, its first task is to generate the audio script. This involves crafting a compelling narrative from the data and using the ElevenLabs API to turn it into speech.
Crafting the Perfect Script Template
Inside your middleware function’s code (e.g., in Python), you’ll parse the incoming event data and insert it into a script template. A good template provides context and feels personal.
# Example in Python within your middleware function
event_data = received_event['payload']
script_text = f"Hi team, a quick sales update. " \
f"{event_data['OwnerName__c']}'s opportunity for {event_data['AccountName__c']}, " \
f"called '{event_data['OpportunityName__c']}', has just moved to the {event_data['StageName__c']} stage. " \
f"The current value is ${event_data['Amount__c']:.2f}. " \
f"The immediate next steps are: {event_data['NextSteps__c']}."
Making the API Call to ElevenLabs
With the script ready, you’ll make a POST request to the ElevenLabs text-to-speech API endpoint. You will need to include your API key in the headers and specify the voice ID you wish to use. Consistently using the same voice ID helps create a recognizable brand persona for your updates. ElevenLabs offers a vast library of ultra-realistic voices to choose from. You can get started and explore their incredible voice library by signing up with a free account.
import requests
ELEVENLABS_API_KEY = "YOUR_ELEVENLABS_API_KEY"
VOICE_ID = "YOUR_CHOSEN_VOICE_ID"
response = requests.post(
f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}",
headers={
"Accept": "audio/mpeg",
"Content-Type": "application/json",
"xi-api-key": ELEVENLABS_API_KEY
},
json={
"text": script_text,
"model_id": "eleven_multilingual_v2",
"voice_settings": {"stability": 0.5, "similarity_boost": 0.75}
}
)
# The response.content will contain the MP3 audio data
audio_content = response.content
To explore their powerful voice generation capabilities, try for free now.
Handling the Audio Output
The API call returns raw audio data. For HeyGen to use it, this audio file must be accessible via a public URL. The best practice is to have your middleware upload this audio content to a cloud storage service like Amazon S3 or Google Cloud Storage and generate a temporary, publicly accessible URL for the file.
Step 3: Creating Personalized Videos at Scale with HeyGen
The final step in our AI content pipeline is generating the video. With the audio URL in hand, the middleware can now make a call to the HeyGen API to bring the update to life.
Choosing Your Avatar and Template
Before making the API call, you should have a video template set up in your HeyGen account. This includes an avatar (you can even create a custom one of a company executive for maximum personalization) and any background or visual elements. Each avatar and template has a unique ID, which you’ll need for the API call.
Integrating the ElevenLabs Audio
To create the video, you’ll make a POST request to HeyGen’s /v2/video/generate
endpoint. The body of the request will specify the avatar, the background, and, most importantly, the audio_url
from the previous step. HeyGen’s API will then fetch the audio from your storage bucket and perfectly lip-sync it with your chosen avatar.
# Example HeyGen API call in Python
HEYGEN_API_KEY = "YOUR_HEYGEN_API_KEY"
AVATAR_ID = "YOUR_AVATAR_ID"
response = requests.post(
"https://api.heygen.com/v2/video/generate",
headers={
"X-Api-Key": HEYGEN_API_KEY,
"Content-Type": "application/json"
},
json={
"video_inputs": [{
"character": {
"type": "avatar",
"avatar_id": AVATAR_ID,
"avatar_style": "normal"
},
"voice": {
"type": "audio",
"audio_url": "URL_TO_YOUR_S3_AUDIO_FILE"
}
}],
"test": False,
"aspect_ratio": "16:9"
}
)
# The response contains the new video_id
video_id = response.json()['data']['video_id']
To see how powerful this is for yourself, you can try HeyGen for free now.
Finalizing and Distributing the Video
Video generation is an asynchronous process. After the initial API call, you will need to poll HeyGen’s video status endpoint using the video_id
until the status is "done"
. Once complete, the API response will contain the final video URL. Your middleware function can then take this URL and complete the workflow by posting it to a designated Slack channel for the sales team, sending it in an email to the relevant manager, or even using the Salesforce API to attach the video link to the opportunity record itself.
By following these steps, you’ve successfully built an end-to-end automation that transforms static Salesforce updates into engaging video content. You’ve brought your CRM data to life. Remember Sarah, the sales director drowning in reports? Now, her phone buzzes with a Slack notification. It’s a one-minute video update: an AI avatar of her company’s CRO detailing a major deal’s progression. She gets all the context she needs instantly, allowing her to send a timely, encouraging message to her sales rep. This is the power of turning static data into dynamic, narrative-driven intelligence.
This powerful automation doesn’t just save time; it transforms how sales teams communicate and operate. By turning static data into dynamic video narratives, you can drive efficiency, improve visibility, and foster a more connected sales culture. Ready to bring your own CRM data to life? Start by exploring the powerful AI voice generation capabilities of ElevenLabs and the seamless video creation platform of HeyGen to build your first automated video workflow today.