0
votes

I've setup the Twilio in salesforce to send the SMS. Twilio is configured perfectly.

The number on which I'm try to send the SMS is also in the supportable country list of alphanumeric sender id list. Country : Lebanon.

when i Put the From number is : like +1 45********. then I'm able to send the SMs. But when i put the From number is "CompanyName", then its not sending SMS.

Error.

The From phone number "CompanyName" is not a valid, SMS-capable inbound phone number or short code for your account.

Please Note: Alphanumeric Sender Id is enabled for my account. Also my account is upgraded.

my code is Below;

 global Static String sendOTP(string PhoneNo){
    Integer rand = Math.round(Math.random()*100000);
    string VerificationCode = string.valueOf(rand);
    String smsBody='Your Verification code is : '+VerificationCode +'. Please don\'t reply.';
    final String  fromNumber = '+14*******';  
    //final String  fromNumber = 'Comapany'; //Not working
    String account = '********';     // Account SID on home tab
    String token   = '*****';  //AUTH Token on home tab
    TwilioRestClient client = new TwilioRestClient(account, token);
    if(PhoneNo != null)

    {
         Map<String,String> params = new Map<String,String> {
        'To'   => PhoneNo, 
        'From' => fromNumber,
        'Body' => smsBody
         };
         try{
         TwilioSMS sms = client.getAccount().getSMSMessages().create(params);
         system.debug('******');
         return VerificationCode;
         }
         catch(Exception e )
         {
            system.debug('@@@@'+e);
          return 'false';
         }   
    }
    return 'false';
}

Please suggest what is the wrong here.

1

1 Answers

0
votes

Twilio developer evangelist here.

The problem is that you are using the deprecated SMS/Messages resource which doesn't support sending by alphanumeric ID. You want to use the Messages resource instead.

Thankfully, the fix is easy, just change

TwilioSMS sms = client.getAccount().getSMSMessages().create(params);

to

TwilioSMS sms = client.getAccount().getMessages().create(params);

The difference there is getSMSMessages is replaced by getMessages.

Let me know if that helps.