0

I am working on a small Salesforce+Twilio integration and need to pass a Salesforce record Id to an SMS recipient, so it's included in their response, and was hoping I can append it to the From: (SenderMobileNumber in my Apex) field.

Is this possible?

4
  • Did you try using message sid?. its a 34 digit id twilio sends. you can store it against the salesforce record and in the response use that to query the salesforce record and perform any operations you want. It is unique.
    – RedDevil
    Commented Jun 26, 2017 at 3:45
  • I did not. In fact I leave this and the ACCOUNT_TOKEN fields alone not having a way to ensure they pass checks on the Twilio side. Are you saying it's possible to end data appended to the SID and then also receive it back in the reply (that I then parse out)?
    – Mike Stan.
    Commented Jun 26, 2017 at 5:10
  • No. Lets say you have an object tracktwilioresponse. Every time you send a SMS twilio gives a message SID. In the object store the messageSID along with other fields you want to. When twilio sends a response query this table with message SID and get all the field values and you need and continue with your processing.
    – RedDevil
    Commented Jun 26, 2017 at 10:51
  • I see. Is the Message SID generated on the Twilio side after I send from Salesforce? If so, how do I get it for one message (we'll probably send 20-30 at a time per day). I also need to get this quick to do the match because the recipients may reply within a few seconds. What does an Apex query look like (if that's the approach)?
    – Mike Stan.
    Commented Jun 26, 2017 at 20:36

1 Answer 1

0

Posting some sample code for illustration purpose.

 TwilioSMS sms = client.getAccount().getSMSMessages().create(params);//line send a request to twilio to send SMS
    system.debug('smsobj' + sms);
     testobj__C SendSMS = new testobj__C(); 
     SendSMS.SMSStatus__c = sms.getStatus();
     SendSMS.Dial_Call_Sid__c = sms.getSid();
     SendSMS.Id = SMSID;
     SendSMS.SMSError__c = '';
     upsert SendSMS;

Once the request is sent to twilio,In the http response you get message status and SID which i store it in my custom object.

Later point where there is a response for the same SMS i can lookup the SID and find the corresponding sObject record and get the values i want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .