Salesforce Twilio Integration

In this blog, I am going to explain how to establish the two-way communication between Salesforce and Twilio. As you all know, communication between any two systems always involves Sends “Request” and receive “Response”. Now we will see how this happens between Salesforce and Twilio
Step 1:
Create a trail account with Twilio. Go to and sign up for free. After that generate your own Twilio number to send SMS to Salesforce and Receive SMS from Salesforce
Step 2:
Create an Apex Controller Class and the VF Page that sends the message to any number by using Twilio REST API. The sample UI can be found below.

The code snippet for the same is available at
Code Walkthrough:
Here is the Twilio Configuration detail


Here is the Sudo code


Step 3: Receiving Inbound message from the Twilio to Salesforce
 To do this simply I build a publicly accessible Rest-based API. In order to build the publicly based API, I created a public facing site and then added the API as public acceptable without any authentication.

Here is the code for the same.


Step 4: Configure the above rest based URI with Twilio.
go to  and Add new message services after that update Twilio outbound message URL with the Salesforce public rest API to receive incoming SMS from Twilio to Salesforce. same is shown in this picture

Step 5:  Explore Twilio Cookies to understand how to map both Sent message and replied messages.

Here is the Git URL for entire project