Your Agent Script agent can talk in a browser voice preview. The next step is a real phone number that anyone can call. That step doesn’t touch your script’s logic.
If you followed along with my previous post, Agentforce Voice for Agent Script: Voice-Enabling Best Practices, you added the voice blocks to a script and tuned its instructions for the ear. This post picks up where that one stopped. It’s for developers who have a voice-ready Agent Script agent and want it to answer real calls. You’ll need an org with the full Agentforce Voice setup, which a free Developer Edition org doesn’t include.
In this post, you’ll look at what your org needs first and how a call reaches your agent. Then you’ll set up the number and routing, and check a call after you hang up.
What does my org need before a call can reach the agent?
You’ll need everything from the previous post: an org with Agentforce Voice turned on, and an Agent Script agent with the language, connection telephony, and modality voice blocks. Phone calls add two more needs: a phone number and an agent user.
You’ll do most of the setup with the Salesforce CLI, from the Salesforce DX project that holds your agent. If you don’t have one yet, create a project in VS Code with the Salesforce Extensions. Then, in the project’s terminal, log in and make the org your default. Replace <your-domain> with your org’s My Domain:
1sf org login web --alias voice-org --set-default --instance-url https://<your-domain>.my.salesforce.comThe commands in this post then leave out --target-org. The checks are SOQL (Salesforce Object Query Language) queries, which you run with sf data query.
A way to get a phone number
Check for this before you start, not halfway through setup. Some orgs have an entitlement that includes a number and inbound voice credits. Query for those two:
1sf data query -q "SELECT MasterLabel, AmountUsed, CurrentAmountAllowed FROM TenantUsageEntitlement WHERE Setting IN ('setting/force.com/orgValue.CountOfTenDLCNumbers', 'setting/force.com/orgValue.InboundVoiceCredits')"You want two rows, “Count of Ten-Digit Long Code Numbers” and “Inbound Voice Credits”, each with a CurrentAmountAllowed above AmountUsed. A blank or a null AmountUsed means none are used yet. If the query returns no rows, talk to your Salesforce account team about adding numbers before you go on.
An agent user
A phone agent must be an Agentforce Service Agent. It runs as its own agent user, not as whoever is logged in, because a caller isn’t logged in to anything. That user has the Einstein Agent User profile, and each one takes an Einstein Agent User license. Make sure you have one available with the following command. UsedLicenses should be lower than TotalLicenses:
1sf data query -q "SELECT UserLicense.Name, UserLicense.TotalLicenses, UserLicense.UsedLicenses FROM Profile WHERE Name = 'Einstein Agent User'"Then create the user with the following command. It prints the new user’s username:
1sf org create agent-userLicenses are limited, so reuse an agent user across rebuilds instead of making a new one each time.
In your Agent Script, set the agent type to AgentforceServiceAgent, and put the new user’s username in access.default_agent_user. It’s the user’s Salesforce username, which looks like an email address but often isn’t one you can email.
1config:
2 developer_name: "VoiceAgent"
3 agent_label: "Voice Agent"
4 agent_type: "AgentforceServiceAgent"
5
6access:
7 default_agent_user: "agent.user.xxxxx@example.com"How does a phone call reach an Agent Script agent?
Three pieces of setup sit between a caller and your script. A call reaches a phone number. A voice channel ties that number to an Omni-Channel flow. The flow routes the call to your agent.
Each piece has one job. The number is the address callers dial. The flow decides who answers. Today, that’s always your agent, but a flow is also where you’d add business hours or more routing rules later. The channel connects the number to the flow, and it’s the switch that turns calls on and off.
Salesforce creates a VoiceCall record for every call. That record travels through the whole chain: the flow receives its ID, and so does your agent. It’s also how you’ll check the call afterwards.
How do I set up the phone number and Omni-Channel routing flow?
The number and the channel live under Agentforce Voice Setup → Voice Channels with Agents, and the flow lives in Flow Builder. Do these in order, because each step needs the one before it.
- Activate your agent. The routing flow can only point at an active agent. If yours isn’t active, it won’t show up when you pick where calls go. You can do this from Agentforce Builder → Select your Agent → Commit → Activate.
- Request a number. Click New Number. A wizard opens in a new window. Pick a country, a number type, and a number. Once you’re done, the number shows as Requested, then Live. It can take a few minutes. Use Refresh Status on the Phone Number tab to check.
- Build the routing flow. It’s a small Omni-Channel flow with one element, which you’ll build in the following section.
- Create and activate the channel. The channel, which you’ll set up in the section after that, ties the number to the flow.
Build the routing flow
You will need an Omni-Channel flow. A few details decide whether calls reach your agent:
- Name the input variable exactly
recordId. Salesforce passes the VoiceCall ID into the flow through that name. Make it a Text variable that’s available for input, or the flow never receives the call. - Keep it to one Route Work element. You need to route a single record (the
recordIdvariable) through a Phone service channel to the Agentforce Service Agent you previously activated. - Set a voice queue as the fallback. It’s where a call lands if the agent can’t take it, so it must be a queue that supports the VoiceCall object. List your voice queues with the following command:
1sf data query -q "SELECT Queue.Name, QueueId FROM QueueSobject WHERE SobjectType = 'VoiceCall'"- Activate the flow, and note its API name. You’ll use the API name to check the flow with a query.
You can also confirm the flow is active from the Salesforce CLI. Replace Voice_Agent_Routing with your flow’s API name:
1sf data query -q "SELECT ApiName, IsActive FROM FlowDefinitionView WHERE ApiName = 'Voice_Agent_Routing'"Create and activate the channel
The channel ties your number to your flow. Getting a number doesn’t create one, so back in Agentforce Voice Setup → Voice Channels with Agents, create a New Channel where you select the Phone Number you previously created and the Omni-Channel flow you just created.
This creates a PSTN Voice channel. PSTN stands for public switched telephone network: the regular phone network.
A new channel is created inactive, and calls won’t reach your agent until you activate it. The channel list doesn’t have a toggle. The Activate button is on the channel’s own page. If your first test call goes nowhere, check this first.
Once it’s active, the channel shows a checkmark in the Active column of the Voice Channels with Agents list:
To check the channel from the Salesforce CLI instead, run the following command. IsActive should be true:
1sf data query -q "SELECT DeveloperName, IsActive FROM MessagingChannel WHERE MessageType = 'PstnVoice'"How do I check a call after I hang up?
To check a call, query its VoiceCall and AgentWork records. A live call doesn’t save a transcript, so these records are how you confirm what happened. First, call the phone number you set up in Agentforce Voice Setup. You should reach your agent.
Don’t worry if the first ring takes a while. Some of that time is spent before the call reaches Salesforce. In testing, Salesforce accepted the call around five seconds after it arrived.
After you hang up, start with the call itself:
1sf data query -q "SELECT Id, FromPhoneNumber, CallAcceptDateTime, CallEndDateTime, CallDurationInSeconds, VendorType FROM VoiceCall ORDER BY CreatedDate DESC LIMIT 1"Check that VendorType is VirtualVoiceAgent, and that FromPhoneNumber is the phone you called from. Then check the routing with the call’s ID:
1sf data query -q "SELECT Status, ServiceChannel.DeveloperName, AcceptDateTime FROM AgentWork WHERE WorkItemId = '<VoiceCall Id>'"The work item should be on sfdc_phone, the developer name of the built-in Phone service channel.
Conclusion
Answering real phone calls doesn’t mean rewriting your Agent Script agent. The work is setup: an agent user, a number, a one-element Omni-Channel flow, and a PSTN Voice channel. Check each call through its VoiceCall and AgentWork records, because a live call doesn’t save a transcript.
With those pieces in place, the agent you voice-enabled in my previous post answers when someone calls. The VoiceCall record also holds the caller’s number, which your agent’s actions can use. That’s a topic for a later post.
Have questions? Ask on the Trailblazer Community or reach out to @SalesforceDevs.
Resources
- Agentforce Voice for Agent Script: Voice-Enabling Best Practices
- Agentforce Voice
- Agent Script (Agentforce Developer Guide)
- Create a Salesforce DX Project in VS Code
- Salesforce CLI Command Reference
- Omni-Channel Flows (Salesforce Help)
- Agent Platform Tracing: Debug Agentforce with Trace Trees, SOQL, and Slack
- Agent Script Recipes (GitHub)
About the author
Alex Martinez was part of the MuleSoft Community before joining Salesforce as a Developer Advocate. Today they help developers build with Agentforce and MuleSoft. You can find more of their content on ProstDev, a site that shares MuleSoft tutorials and walkthroughs. Follow Alex on LinkedIn.

