Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A Salesforce/ library for communicating with the Twilio REST API and generating TwiML. Need help? Post your questions to or email us at
Branch: master

Create v4 Release Notes

Basic description of release
latest commit a1ea9ae7c6
@hhai hhai authored


Twilio Helper Library for Salesforce

Get ready to unleash the power of the Twilio cloud communications platform in Salesforce and! Soon you'll be building powerful voice and text messaging apps in Apex and Visualforce.

With this toolkit you'll be able to:

  • Make requests to Twilio's REST API
  • Control phone calls and respond to text messages in real time with TwiML
  • Embed Twilio Client in-browser calling in your Salesforce and apps


We've made it easy to get started. Just grab the code from GitHub and deploy it to your Salesforce org with the included Ant script.

Quick Install: If you do not have the existing Twilio-Salesforce library installed, you can use this unmanaged package to install: v4.0.0


If you have a previous version of Twilio-Salesforce library installed, you will need to use Ant to install/update:

  1. Checkout or download the twilio-salesforce library from GitHub.

    $ git clone
  2. Install the Migration Tool plugin for Ant, if you don't already have it.

  3. Edit install/ to insert your Salesforce username and password. Since you will be using the API to access Salesforce, remember to append your Security Token to your password.

  4. Open your command line to the install folder, then deploy using Ant:

    $ ant deployTwilio

Now all the library code is in your org and you're ready to start coding!


Getting started with the Twilio API couldn't be easier. Create a Twilio REST client to get started. For example, the following code makes a call using the Twilio REST API.

Make a Call

This sample calls the to phone number and plays music. The from number must be a verified number on your Twilio account.

// Find your Twilio API credentials at

TwilioRestClient client = new TwilioRestClient(account, token);

Map<String,String> params = new Map<String,String> {
        'To'   => '9991231234',
        'From' => '9991231234',
        'Url'  => ''
TwilioCall call = client.getAccount().getCalls().create(params);

Send an SMS

This sample texts Hello there! to the to phone number. The from number must be a number which you have purchased from Twilio. Unlike voice calls, SMS messages cannot be sent from a verified number.

TwilioRestClient client = new TwilioRestClient(account, token);

Map<String,String> params = new Map<String,String> {
        'To'   => '+12316851234',
        'From' => '+15555555555',
        'Body' => 'Hello there!'
TwilioSMS sms = client.getAccount().getSMSMessages().create(params);

Generate TwiML

To control phone calls, your application needs to output TwiML. Use TwilioTwiML.Response to easily create a TwiML document.

TwilioTwiML.Response r = new TwilioTwiML.Response();
TwilioTwiML.Play p = new TwilioTwimL.Play('');
<Response><Play loop="5"></Play><Response>

Next Steps

The full power of the Twilio API is at your fingertips. Visit the full documentation for advanced topics.

Something went wrong with that request. Please try again.