Send Bulk SMS Messages
Follow the steps below to sending SMS messages in bulk for all records that correspond to a particular Contact object.
- Create a List of type smagicinteract__smsMagic__c.
- Iterate the contact list.
- Create an object of smagicinteract__smsMagic__c.
- Assign fields to the object.
- Iterate through and perform the SMSCallout to send the SMS.
- 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);