PushSMSCallout

May 16, 2014
admin
PushSMSCallout

 This is API to send SMS. This will not create records of smsMagicObject inside your salesforce organization. PushSMSCallout used for sending bulk SMS.PushSMSCallout is not a future method and is it not mandatory method in order to send out messages.

ApexAPI class contains “pushSMSCallout()” static method which accepts the list of objects of smagicinteract__smsMagic__c and returns the response as text.

 You can use this API as -

String responseText = smagicinteract.ApexAPI.pushSMSCallout(smsObjectList);

Two ways to use Push SMS Callout.

1. When we call from trigger we have to used future annotation ( @future(callout=true) ). This is required as salesforce does not permits us to make callout directly from a trigger.

see the below example

trigger SendSmsToContact on Contact (after insert) {
List conList=Trigger.new;
List<id> idList=new List();
for(Contact key:conList){
idList.add(key.id);
}
sendSmsToContactHelperClass.sendSms(idList);
}

public class SendSmsToContactHelperClass {

@future(callout=true)
public static void sendSms(List idList){
String query='select id,MobilePhone,Name from Contact where id in : idList';
List<contact> conList=Database.query(query);
List<smagicinteract__smsmagic__c> smsObjectList = new List<smagicinteract__smsmagic__c>();
String templateText = 'test SMS by Screen Magic';
String senderId = 'smsMagic';
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);

}
}

2. When we do not call from a trigger its a direct callout.

String query='select id,MobilePhone,Name from Contact where id in : idList';
List<contact> conList=Database.query(query);
List<smagicinteract__smsmagic__c> smsObjectList = new List<smagicinteract__smsmagic__c>();
String templateText = 'test SMS by Screen Magic';
String senderId = 'smsMagic';
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);

What will be alternative method for “PushSMSCallout”

If you do not want to use pushsmscallout then use send sms code of trigger to send out sms. When you insert sms history record it invokes a trigger code which will send out sms to your customer/user. To use this you will have set the value of disablesmsonTrigger to 0.

Below is a sample code.

String query='select id,MobilePhone,Name from Contact where id in : idList';
List<contact> conList=Database.query(query);
List<smagicinteract__smsmagic__c> smsObjectList = new List<smagicinteract__smsmagic__c>();
String templateText = 'test SMS by Screen Magic';
String senderId = 'smsMagic';
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 =0;
smsObject.smagicinteract__external_field__c =
smagicinteract.ApexAPI.generateUniqueKey();
smsObject.smagicinteract__SMSText__c = templateText;
smsObjectList.add(smsObject);
}
}
Database.insert(smsObjectList,false);
Limitation :

Maximum size of callout request or response= 3 MB

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>