1

Alphabetical sender id is not sending SMS by Twilio

0 down vote favorite 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.

  • This seems rather an issue with Twilio than Salesforce, so Id open a case with them. Have you tried any other way except the Apex Wrapper to send the very same SMS? My guess is Lebanon might not support the alpha numeric sender despite docs saying otherwise. – Christian Szandor Knapp Aug 17 '17 at 10:00
1

As per the Twilio Support, twilio-salesforce helper library is unfortunately out-dated,thus it will not support the alphanumeric sender Id functionality.

But what you can do instead is use direct request in your code, which should use correct endpoint:

/ Add your Account SID and Auth token values below
String account_sid = 'ACxxxxxxxxxxxx';
String auth_token = 'xxxxxxxxxxxxxxxxx';

HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.twilio.com/2010-04-01/Accounts/'+ account_sid 
+'/Messages');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');

Blob headerValue = Blob.valueOf(account_sid + ':' + auth_token);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);

req.setHeader('Authorization', authorizationHeader);
req.setBody('To=%2145xxxxx&From=%2B145xxxxxx&Body=Testing ABC');

Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());

This way you should be able to use also Alphanumeric sender ID!

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.