Send Bulk SMS Messages

Follow the steps below to sending SMS messages in bulk for all records that correspond to a particular Contact object.

  1. Create a List of type smagicinteract__smsMagic__c.
  2. Iterate the contact list.
  3. Create an object of smagicinteract__smsMagic__c.
  4. Assign fields to the object.
  5. Iterate through and perform the SMSCallout to send the SMS.
  6. Finally, use database.insert to insert the object list.

Here is some example code that sends bulk SMS messages.

List smsObjectList = new List();
List  conList; //List of contact populated from the visual force page or fetch from the database.
String templateText = 'test SMS by Screen Magic';
String senderId = 'smsMagic'; // Please replace the 'smsMagic' with your relevant sender ID.
for(Contact contact :conList){
   smagicinteract__smsMagic__c smsObject = new smagicinteract__smsMagic__c();
   if(contact.MobilePhone != null){
 
     smsObject.smagicinteract__SenderId__c = senderId;
     smsObject.smagicinteract__PhoneNumber__c = contact.MobilePhone;
     smsObject.smagicinteract__Name__c = contact.Name;
     smsObject.smagicinteract__ObjectType__c = 'Contact';
     smsObject.smagicinteract__disableSMSOnTrigger__c = 1;
     smsObject.smagicinteract__external_field__c =
     smagicinteract.ApexAPI.generateUniqueKey();
     smsObject.smagicinteract__SMSText__c = templateText;
     smsObjectList.add(smsObject);
   }
}
/*
 * Note : When you are using pushSMSCallout method to send the SMS
 *        please make sure that smagicinteract__disableSMSOnTrigger__c
 *        should have value as 1.
 */
String response = smagicinteract.ApexAPI.pushSMSCallout(smsObjectList);
Database.insert(smsObjectList,false);

Was This Article Helpful?

xTo test this chatbot, please submit your details on this page
Note: After submitting your details you will be redirected to this page and access chatbot