At some point we lost the Vf page and ability to send SMS messages using the Apex below and I'm having problems re-creating a Vf page. Can you help?

It looks like the Vf page was very simple and should:

  • look up Contacts who are tagged as a TwilioRegisteredUser (see query in GetPersonList method)
  • Recognize MobilePhone
  • Have a text area for the message
  • Have a button to send message

Here's the Apex class:

public with sharing class TwilioCloudCommunicationClass { 

// Public Properties  
public String SelectedMobileNumber{get;set;}  
public String OtherMobileNumber{get;set;}  
public String textMessage{get;set;}  

// Default construtor  
public TwilioCloudCommunicationClass()  
    SelectedMobileNumber  = '' ;  
    OtherMobileNumber = '' ;  

Public List<SelectOption> getPersonList()
        List<SelectOption> localList = new List<SelectOption>();  
        localList.add(new SelectOption('' , '--Select--'));  
        for(contact cont : [select Name,MobilePhone from contact where TwilioRegisteredUser__c = true ])  
            localList.add(new SelectOption(cont.MobilePhone , cont.Name));            
        localList.add(new SelectOption('other' , 'Other'));  
        return localList ;  
    catch(Exception e)  
        return null;  

public void SendSMS()  
        SelectedMobileNumber = (SelectedMobileNumber == '')? OtherMobileNumber:SelectedMobileNumber ;  
        if(SelectedMobileNumber != '')  
            List<TwilioConfig__c> AdminInfo = TwilioConfig__c.getall().values();
            String ACCOUNT_SID = '';  
            String AUTH_TOKEN  = '' ;              
            String SenderMobileNumber = '' ;  
            // Informaton getting from custom setting  
                ACCOUNT_SID             = AdminInfo[0].AccountSid__c;  
                AUTH_TOKEN              = AdminInfo[0].AuthToken__c;                  
                SenderMobileNumber      = AdminInfo[0].Admin_Mobile_Number__c;      
            TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);  

            Map<String, String> properties = new Map<String, String> { 
                        'To'  => SelectedMobileNumber , 
                        'From' => SenderMobileNumber, 
                        'Body' => textMessage   
            TwilioSMS message = client.getAccount().getSmsMessages().create(properties);  
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'Message has been sent'));  
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, 'Please provide valid Mobile Number '));  
    }catch(Exception e )  
        return ;  


Many thanks.


Always happy to give some Twilio love here...

This seems to work for me, though I don't have Twilio installed in my org:

<apex:page controller="TwilioCloudCommunicationClass" cache="false">
        <apex:actionFunction name="RefreshNumber" rerender="sms" >
              <apex:param name="firstParam" assignTo="{!SelectedMobileNumber}" value="" />
                <apex:commandButton action="{!SendSMS}" value="Send SMS"/>
            <apex:pageBlockSection id="sms">
                <apex:outputLabel>Contact to Text</apex:outputLabel>
                <apex:selectList size="1" onchange="RefreshNumber(this.value)">
                    <apex:selectOptions value="{!PersonList}"/>
                <apex:outputLabel>Selected Number</apex:outputLabel>
                <apex:inputText value="{!SelectedMobileNumber}"/>
                <apex:outputLabel>Use Other Number</apex:outputLabel>
                <apex:inputText value="{!OtherMobileNumber}"/>
                <apex:outputLabel>Message to Send</apex:outputLabel>
                <apex:inputTextarea value="{!textMessage}"/>
|improve this answer|||||
  • 1
    Thank you so much - looks/works better than screenshot of their original! – Mike Stan. Jun 15 '17 at 2:45
  • As nice as we got the form and button to look on our page, we'd like to automate the sending of SMS messages using workflows. What' approach should I take to pull in an Id for a class enrollment, phone number to send text to, Name, and class date - all from custom objects (we do not use any of the Sf standard objects for this (NPO only uses them for donations and Volunteers). I appreciate your input. – Mike Stan. Jun 26 '17 at 6:09
  • I would probably look at some form of queueable job, or maybe create an invocable class you can call from Process Builder? – BritishBoyinDC Jun 28 '17 at 1:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.