function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TreemanTreeman 

LiveMessage API reacts differently in an asynchronous (i.e. @future) call

I know that there is limited "community knowledge" associated with LiveMessage (formerly LiveText from Heywire), but I'm hoping someone (including LiveMessage engineers) can shed some light on an issue I am experiencing.

By way of background - I am attempting to call the LiveText global methods directly (vs. using Process Builder based processes) because I need to do a callout first to shorten a dynamic URL (I am calling bit.ly's URL Shortener API to shorten a Sites based URL that includes dynamic parameters).

If I execute my code synchronously (i.e. via Anonymous Apex) I receive the expected SMS/text message to my mobile phone; however, if I execute the exact same code asynchonously (i.e. via an @future based class) nothing happens, and I don't receive an exception or anything in the 'ActionResult' return.

Here is an applicable code snippet (the last portion is all about sending the results via an email message):

Case cj = [Select Id, AccountId, CaseNumber, CJDT_Exp_Offer_SMS__c, CJDT_Std_Offer_SMS__c, CJDT_Time_Change_SMS__c, 
     Clean_Date__c,  Clean_Job_Date_Time__c, Cleaner_Source__c, Cleaning_Offer_Expiration__c, CleanJobOffers_URL__c, ContactId, 
     Contact.MobilePhone, ContactMobilePhone__c,Disable_Clean_Job_SMS__c, Earliest_Clean_Start__c,  Earliest_Clean_Start_local__c, 
     Hours_Until_Clean__c, IsClosed, Latest_Clean_End__c, Latest_Clean_End_local__c, Next_Reservation__c, Reservation__c, 
     SMS_Cancellation__c, SMS_Clean_Not_Started__c, SMS_Expedited_Offer__c, SMS_Outbound_CJ_Number__c, 
     SMS_Reclean_Request__c,  SMS_Standard_Offer__c, SMS_Time_Change__c, SMS_URL_Accept__c, SMS_URL_Decline__c, Status,
     Subject, Type, Unit__c, Unit_Email__c, Unit__r.Building__r.TimeZone__c, Unit__r.City__c, Unit__r.Cleaner_Primary__c,
     Unit__r.Cleaner_Secondary__c, Unit__r.Unit_Email__c, Unit__r.Name, Unit__r.PostalCode__c, Unit__r.State_Province__c, Unit__r.Street__c,
     Unit__r.UnitNumber__c from Case where Id = '5000m00000310PaAAI'];

list<LiveText.ScheduleItem> schedMsgs = new list<LiveText.ScheduleItem>();

LiveText.ScheduleItem schedItem = new LiveText.ScheduleItem();
schedItem.ObjectId =cj.Id;
schedItem.ReferenceId = cj.Id + ' - Standard Offer';
schedItem.LiveTextNumber = cj.SMS_Outbound_CJ_Number__c;
schedItem.ToPhoneNumber = cj.ContactMobilePhone__c;
schedItem.Message = cj.SMS_Standard_Offer__c;
schedItem.BypassOptinCheck = true;
schedMsgs.add(schedItem);

//send SMS Messages
if(schedMsgs.size()>0){
    String htmlBody = 'Scheduled Messages: '+schedMsgs;
    list<LiveText.ActionResult> results = new list<LiveText.ActionResult>();
    try{
          results = LiveText.ScheduleMessageAction.scheduleMessages(schedMsgs);
          htmlBody += '<BR></BR><BR></BR>Results: ' + results;
    }
    catch(Exception e){
          htmlBody += '<BR></BR><BR></BR>Exception: ' + e.getMessage();
    }
String subject = '** LiveMessage Schedule Messages Result **';
for(LiveText.ActionResult ar:results){
htmlBody += '<BR></BR>Results: ' +  ar.ErrorMessage + ' | IsSuccess: ' + ar.IsSuccess;
}
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {'gary@paralleltravel.co'});
mail.setReplyTo('gary@paralleltravel.co');
mail.setSenderDisplayName('Gary Triassi');
mail.setSubject(subject);
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setHtmlBody(htmlBody);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

The email I receive via Anonymous Apex is:

Scheduled Messages: (ScheduleItem:[BypassOptinCheck=true, EnforceObjectPresence=null, IsAlterScheduleBasedOnReferenceId=null, LiveTextNumber=(209) 418-0548, Message=STANDARD OFFER 00001118/Regular 03/01/18 11:00-23:59 DALVPL1210 Accept (00001118):http://bit.ly/2ETjOhX Decline (00001118): http://bit.ly/2ETjPm1, MessageSource=null, ObjectId=5000m00000310PaAAI, ReferenceId=5000m00000310PaAAI - Standard Offer, ScheduleDate=null, ToPhoneNumber=(925) 699-4740, UseQueueable=null])

Results: (ActionResult:[ErrorMessage=null, IsSuccess=true, Tag=5000m00000310PaAAI])
Results: null | IsSuccess: true

The result received via the @future call is:

Scheduled Messages: (ScheduleItem:[BypassOptinCheck=true, EnforceObjectPresence=null, IsAlterScheduleBasedOnReferenceId=null, LiveTextNumber=(209) 418-0548, Message=STANDARD OFFER 00001118/Regular 03/01/18 11:00-23:59 DALVPL1210 Accept (00001118):http://bit.ly/2ETjOhX Decline (00001118): http://bit.ly/2ETjPm1, MessageSource=null, ObjectId=5000m00000310PaAAI, ReferenceId=5000m00000310PaAAI - Standard Offer, ScheduleDate=null, ToPhoneNumber=(925) 699-4740, UseQueueable=null])

Results: ()

All thoughts and suggestions are greatly welcomed!!
Dev AngelDev Angel
Hi Treeman,

Thanks for posting this. We are currently investigating to determine if this is LiveMessage or Apex related.