Menu

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Using Twilio REST APIs from Apex

The Twilio for Salesforce package includes an Apex helper class that reduces the amount of code needed to interact with Twilio APIs. While the Lightning Components in the package focus on SMS only, the helper class allows you to write custom Apex to interact with any of Twilio's API services, such as Voice and Chat.

Note: code samples are written in Apex, but are labeled as "Java" for syntax highlighting purposes.

        
        
        
        

        Twilio will verify that you've included a valid Twilio phone number in the From parameter, and then either queue the call or return an error.

        Check out the full API Reference for Messages for the full list of parameters you can include in your request. You can add these using the addUrlPart method. You can also find the parameters you can expect back from Twilio.

              
              
              
              

              Use TwilioApiClientResponse to retrieve the status code and error message from your request.

                    
                    
                    
                    

                    This example shows how to pull a list of messages from Twilio. By default, this method will return 50 results. The maximum number of records in a single request is 1000. You can set how many results are returned using the pageSize param.

                    See the "Get Messages with Pagination" examples for pulling larger groups of messages.

                          
                          
                          
                          

                          This example demonstrates how to retrieve a list of messages that match specified criteria. See this documentation to view additional options for filtering messages.

                                
                                
                                
                                

                                Get all messages in your Twilio account using pagination. In this example, we get the next page URL if it exists and then call it in our Twilio client.

                                      
                                      
                                      
                                      
                                            
                                            
                                            
                                            

                                            Basic example of message deletion.

                                                  
                                                  
                                                  
                                                  

                                                  A Messaging Service is a pool of phone numbers that properly encodes your message body, matches the recipients area code, and distributes SMS across multiple numbers. You can read more about Messaging Services here.

                                                  This code example demonstrates how to get a list of Messaging Services in your account.

                                                        
                                                        
                                                        
                                                        

                                                        This example shows how to update the “Friendly Name” of a Messaging Service using the Twilio API.

                                                              
                                                              
                                                              
                                                              

                                                              Taskrouter is an API for tracking the availability of call center workers and routing tasks to the appropriate worker. In this example, we are pulling the current list of open ("reserved") tasks for an individual worker.

                                                              Need some help?

                                                              We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.