Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    • Enhancing Performance with File Compression in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Friday, May 16
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Apex»Integrate Salesforce with WhatsApp using Twilio API

    Integrate Salesforce with WhatsApp using Twilio API

    Dhanik Lal SahniBy Dhanik Lal SahniSeptember 6, 2019Updated:December 10, 202431 Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Integrate Salesforce with WhatsApp using Twilio API
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Businesses must send instant notifications to customers for real-time updates or personalized services using WhatsApp. Salesforce provides functionality to send WhatsApp messages using Social Studio. If we don’t have a Social Studio license then we can utilise Twilio API to send WhatsApp messages. This post will provide complete details about sending WhatsApp messages from the Lightning Application by Integrating Salesforce and WhatsApp using Twilio API.

    Steps for Twilio API integration in Salesforce:

    1. Signup in Twilio 
    2. Create Sandbox environment
    3. Create Apex for consuming API
    4. Create Lightning component

    1. Signup in Twilio 

    Sign up in Twilio to integrate it with the Salesforce application.

    It will send one verification email to verify the email. Verify email to continue. This will open the below screen to verify the phone number.

    Verify mobile/phone number to process further.  After verification and confirming the required information, this popup will show. Confirm this also as it is for developers to test Whatsapp messaging.

    2. Create Sandbox environment

    Developers can test WhatsApp messaging using the Sandbox environment.  Setting the Sandbox environment is 4 steps process and it will start after the above popup is confirmed.

    The first step is to connect the sandbox environment with your Whatsapp number. So send the message ‘join <connection code>’ to +14155238886. Connection code will be generated automatically and it will be visible on pages like in below page with bold characters. For my test environment, it is difficult-now.

    Once you send a proper message, it will link your WhatsApp number to the sandbox environment.

    In the next step, send any message from the sandbox environment to your WhatsApp number. You can select any option to test like ‘Appointment Reminder’, ‘Order Notifications’ and ‘Verification Codes’.

    Send WhatsApp using Twilio API

    The below screen shows, how the message will be delivered to your number.

    Send WhatsApp Message in Salesforce

    After confirming that the message has been delivered to your WhatsApp number, you can proceed to the next step. The next step is to send a message from your WhatsApp number to verify two-way communication.

    After successful communication, it will show the sandbox environment detail. For testing, we can only use 3 highlighted message formats.

    Now our sandbox environment is set up. Let us proceed with using Twilio API in Apex.

    3. Create Apex for consuming API

    Integrate Twilio API to send WhatsApp messages using Apex. Apex needs your Twilio account SID and secret token. You can get this information here. If it is not available by default then click Show API Credentials on the right side of the page.

    Add Twilio API Url in Remote Site Setting.


    Sending messages will require three parameters.

    • From: This is the sender’s WhatsApp number.  For the sandbox environment, this number will be  +14155238886.
    • To: This is the receiver’s WhatsApp number.  Use the above WhatsApp number which you have configured in a sandbox environment.
    • Body: This is the message which will be sent. For testing use the format which is mentioned on the sandbox page.

    4. Create a Lightning component

    Create a lightning component to send messages using the above apex class.

    Provide the receiver’s WhatsApp number and message in a valid format. It will send a WhatsApp message to the provided number.

    If you need to send WhatsApp message to other mobile number then it should be verified first. You can verify mobile no here.

    Reference: https://www.twilio.com/docs/sms/whatsapp

    Other Useful Posts

    • Implementing Apex Cursors for Optimal Resource Management in Salesforce
    • Efficient Ways to Debug Salesforce Platform Events
    • How to Use Image Cropper in Salesforce Lightning Web Component
    • Appointment Assistance Real Time Location Url Generation
    • Setting Up Live Chat with Salesforce Messaging
    • Top Developer Features in Salesforce Spring ’24 Release

    apex lightning salesforce twilio
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleCapture Screen using Lightning Component
    Next Article Capture Image using WebCAM in Lightning Component
    Dhanik Lal Sahni
    • Website

    Related Posts

    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    By Dhanik Lal Sahni5 Mins Read

    How to Implement Dynamic Queueable Chaining in Salesforce Apex

    April 21, 2025
    View 31 Comments

    31 Comments

    1. sakshi on November 8, 2019 5:47 pm

      Hi Dhanik, in apex controller, name of method should be SendMessage i guess. can you please confirm

      Thanks

      Reply
      • Dhanik Lal Sahni on November 11, 2019 8:56 pm

        Yes Sakshi. Thank you for informing. I have updated it.

        Reply
    2. sumit on December 16, 2019 3:27 pm

      how to receive message/incoming message from whatsapp

      Reply
      • Dhanik Lal Sahni on May 3, 2020 9:13 am

        Hello Sumit,

        Twilio has both functionality to receive and send SMS. Refer link

        Thank You,
        Dhanik

        Reply
    3. sumit on December 16, 2019 3:28 pm

      Hi Dhannik,
      Your post is very nice but i need some help. i want show incoming message from user devive in saleforce component so how to receive message/incoming message from whatsapp

      Reply
      • Dhanik Lal Sahni on May 3, 2020 9:12 am

        Hello Sumit,

        Twilio has both functionality to receive and send SMS. Refer link

        Thank You,
        Dhanik

        Reply
        • Basavaraj on October 10, 2022 12:09 pm

          Hi Dhanik,

          Please, Can you help me in Received messages storing in database of salesforce.

          Thank you

          Reply
          • Dhanik Lal Sahni on October 15, 2022 9:47 pm

            Hello Basavaraj,
            You can use any Custome Object to store messages. Still, if you need to discuss then ping me on Linkedin or telegram.

            Thank You,
            Dhanik

            Reply
    4. Kumar on April 20, 2020 5:58 am

      does this requires twilio for salesforce appexchange product installed to access twilio outbound api call or its public api. Thanks for the post.

      Reply
      • Dhanik Lal Sahni on April 28, 2020 12:59 am

        Hello Kumar,

        It is accessing twilio api. No need to install App-exchange product.

        Thank You,
        Dhanik

        Reply
    5. RSN on June 16, 2020 8:27 pm

      Hello,
      I want to give it a shot, will it work with a developer org?

      Reply
      • Dhanik Lal Sahni on June 17, 2020 12:36 am

        Yes, It will work for developer org.

        Thank You,
        Dhanik

        Reply
    6. Manvendra on August 1, 2020 7:18 pm

      Hi Dhanik ,

      I am getting below error when I am trying to send SMS via apex using above code .
      {“code”: 21211, “message”: “The ‘To’ number Wtatsapp:+91XXXXXXXXXX is not a valid phone number.”, “more_info”: “https://www.twilio.com/docs/errors/21211”, “status”: 400}

      Can you confirm if I am missing anything?
      A quick response will be highly appreciated.

      Reply
      • Dhanik Lal Sahni on August 1, 2020 9:25 pm

        Hello Manav,

        You have to verify the mobile number where you are sending SMS. Let me know if this still not work. We can connect and resolve your issue.

        Thank You,
        Dhanik

        Reply
    7. Manvendra on August 3, 2020 11:41 am

      Thanks Dhanik for guiding me, its working fine now

      Reply
    8. Harshal Gosavi on May 26, 2021 3:38 pm

      Hello Dhanik,
      I am trying to get all messages from Twilio to salesforce. So i used ‘GET’ method for it, but in response Twilio only send the latest single message. Can you please help me out?

      Reply
      • Dhanik Lal Sahni on June 5, 2021 7:36 pm

        Hello Harshal,

        Please check https://www.twilio.com/docs/sms/api/message-resource#read-multiple-message-resources for getting all messages.

        Thank you,
        Dhanik

        Reply
    9. ifthikar on August 18, 2021 10:58 am

      Hi Dhanik,

      How to send multimedia messages

      Reply
      • Dhanik Lal Sahni on August 20, 2021 9:03 pm

        Hello Ifthikar,

        Checkout this page from Twilio for MMS support.

        Thank You,
        Dhanik

        Reply
    10. Pingback: Generate OTP in LWC | SalesforceCodex

    11. Akash Dhole on February 15, 2022 7:03 pm

      I am getting an error
      18:57:04:772 USER_DEBUG [29]|DEBUG|{“code”: 63007, “message”: “Twilio could not find a Channel with the specified From address”, “more_info”: “https://www.twilio.com/docs/errors/63007”, “status”: 400}
      18:57:04:773 USER_DEBUG [35]|DEBUG|Twilio errorTwilio could not find a Channel with the specified From address

      And Can you Please tell me In Status Callback URL Which URL I Should used

      Reply
      • Dhanik Lal Sahni on February 15, 2022 8:17 pm

        Hey Akash,

        Please check this post

        Thank You,
        Dhanik

        Reply
    12. Pramod on March 14, 2022 3:09 am

      Hi ,
      Hi Dhanik ,

      I am getting below error and also verified my number as well.

      {“code”: 63007, “message”: “Twilio could not find a Channel with the specified From address”, “more_info”: “https://www.twilio.com/docs/errors/63007”, “status”: 400}
      Can you please help me out? Thanks!

      Reply
      • Dhanik Lal Sahni on March 25, 2022 9:06 pm

        Hello Pramod,
        Please check this blog https://support.twilio.com/hc/en-us/articles/360009017394-Troubleshooting-the-Twilio-Sandbox-for-WhatsApp#:~:text=Error%3A%20Twilio%20could%20not%20find,message%20is%20not%20formatted%20correctly.

        Thank You,
        Dhanik

        Reply
    13. Kannan on April 10, 2022 11:31 am

      Hi Dhanik,
      can you please share the get message code and aura modification for this

      Reply
      • Dhanik Lal Sahni on April 18, 2022 11:20 am

        Hello Kannan,

        You can include this LWC in your aura as well. Any specific reason, only to create in Aura component?

        Thank You,
        Dhanik

        Reply
    14. ANKIT on April 24, 2022 12:25 pm

      Hi Dhanik,

      To connect sandbox with my number, it should show join . In my case, it’s only showing join not sandbox name to send a message. I tried sending join but there is no sandbox name, do you have any idea why my sandbox name not coming.

      Thanks

      Reply
      • Dhanik Lal Sahni on May 6, 2022 10:43 am

        Hello Ankit,

        Try to create a new user and connect. I hope, it will resolve. Otherwise, we can connect to resolve your issue.

        Thank You,
        Dhanik

        Reply
    15. Pingback: Difference between SOAP and REST API? - SalesforceCodex

    16. Samir Nagesh Sahare on December 7, 2022 6:37 pm

      Please help me to send a WhatsApp message to other mobile numbers or how to add mobile numbers in Twilio.

      Reply
      • Dhanik Lal Sahni on December 7, 2022 7:57 pm

        Hello Samir,

        What issue you are facing. Please let me know so that i can help you. You can also refer video which is covering your issue as well.

        Thank You,
        Dhanik

        Reply
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.