{"id":1397,"date":"2020-07-24T11:10:23","date_gmt":"2020-07-24T11:10:23","guid":{"rendered":"https:\/\/staging.txtbox.in\/docs\/developers\/?post_type=lsvr_kba&#038;p=1397"},"modified":"2020-07-24T11:10:24","modified_gmt":"2020-07-24T11:10:24","slug":"pushsmscallout","status":"publish","type":"lsvr_kba","link":"https:\/\/staging.txtbox.in\/docs\/developers\/knowledge-base\/pushsmscallout\/","title":{"rendered":"PushSMSCallout"},"content":{"rendered":"\n<p>The purpose of this API resource is to send SMS messages in bulk. It does not create records of smsMagicObject inside your Salesforce organization.<\/p>\n\n\n\n<p>The Apex API class contains a\u00a0<strong>pushSMSCallout()<\/strong>\u00a0static method, which accepts the list of objects in\u00a0<strong>smagicinteract__smsMagic__c<\/strong>\u00a0and returns a text response.<\/p>\n\n\n\n<p>You can use this API resource as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">String responseText = smagicinteract.ApexAPI.pushSMSCallout(smsObjectList);<\/pre>\n\n\n\n<p>There are two ways to use\u00a0<strong>PushSMSCallout<\/strong>.<br>1. When we call from a trigger, it\u2019s necessary to use future annotation<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@future(callout=true)<\/pre>\n\n\n\n<p>This is necessary because Salesforce does not permit making a callout directly from a trigger. Here is a code example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">trigger SendSmsToContact on Contact (after insert) {\nList conList=Trigger.new;\nList idList=new List();\n \nfor(Contact key:conList){\nidList.add(key.id);\n}\nsendSmsToContactHelperClass.sendSms(idList);\n}\n \npublic class SendSmsToContactHelperClass {\n@future(callout=true)\npublic static void sendSms(List idList){\nString query='select id,MobilePhone,Name from Contact where id in : idList';\nList conList=Database.query(query);\nList smsObjectList = new List();\nString templateText = 'test SMS by Screen Magic';\nString senderId = 'smsMagic'; \/\/ Please replace the 'smsMagic' with your relevant sender ID.\n \nfor(Contact contact:conList){\nsmagicinteract__smsMagic__c smsObject = new smagicinteract__smsMagic__c();\nif(contact.MobilePhone != null){\nsmsObject.smagicinteract__SenderId__c = senderId;\nsmsObject.smagicinteract__PhoneNumber__c =contact.MobilePhone;\nsmsObject.smagicinteract__Name__c =contact.Name;\nsmsObject.smagicinteract__ObjectType__c = 'Contact';\nsmsObject.smagicinteract__disableSMSOnTrigger__c =1;\nsmsObject.smagicinteract__external_field__c =\nsmagicinteract.ApexAPI.generateUniqueKey();\nsmsObject.smagicinteract__SMSText__c = templateText;\nsmsObjectList.add(smsObject);\n}\n}\n \n\/*\n* Note : When you are using pushSMSCallout method to send the SMS\n* please make sure that smagicinteract__disableSMSOnTrigger__c\n* should have value as 1.\n*\/\nString response = smagicinteract.ApexAPI.pushSMSCallout(smsObjectList);\nDatabase.insert(smsObjectList,false);\n}\n}\n<\/pre>\n\n\n\n<p>2. The other way to use&nbsp;<strong>PushSMSCallout<\/strong>&nbsp;is a direct callout\u2013when we do not call from a trigger. Here is a code example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">String query='select id,MobilePhone,Name from Contact where id in : idList';\nList conList=Database.query(query);\nList smsObjectList = new List();\nString templateText = 'test SMS by Screen Magic';\nString senderId = 'smsMagic'; \/\/ Please replace the 'smsMagic' with your relevant sender ID.\nfor(Contact contact:conList){\nsmagicinteract__smsMagic__c smsObject = new smagicinteract__smsMagic__c();\nif(contact.MobilePhone != null){\nsmsObject.smagicinteract__SenderId__c = senderId;\nsmsObject.smagicinteract__PhoneNumber__c =contact.MobilePhone;\nsmsObject.smagicinteract__Name__c =contact.Name;\nsmsObject.smagicinteract__ObjectType__c = 'Contact';\nsmsObject.smagicinteract__disableSMSOnTrigger__c =1;\nsmsObject.smagicinteract__external_field__c =\nsmagicinteract.ApexAPI.generateUniqueKey();\nsmsObject.smagicinteract__SMSText__c = templateText;\nsmsObjectList.add(smsObject);\n}\n}\n\/*\n* Note : When you are using pushSMSCallout method to send the SMS\n* please make sure that smagicinteract__disableSMSOnTrigger__c\n* should have value as 1.\n*\/\nString response = smagicinteract.ApexAPI.pushSMSCallout(smsObjectList);\nDatabase.insert(smsObjectList,false);\n<\/pre>\n\n\n\n<p><strong>Alternative method for PushSMSCallout<\/strong><br>If you do not want to use&nbsp;<strong>PushSMSCallout<\/strong>, you can use the&nbsp;<strong>SendSMS<\/strong>&nbsp;code of trigger to send out SMS. When you insert an&nbsp;<strong>SMSHistory<\/strong>&nbsp;record, it invokes a trigger code \u2013 which will send out an SMS message to your recipient. You\u2019ll need to set the value of&nbsp;<strong>disablesmsonTrigger<\/strong>&nbsp;to 0.<br>Below is a sample code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">String query='select id,MobilePhone,Name from Contact where id in : idList';\nList conList=Database.query(query);\nList smsObjectList = new List();\nString templateText = 'test SMS by Screen Magic';\nString senderId = 'smsMagic'; \/\/ Please replace the 'smsMagic' with your relevant sender ID.\nfor(Contact contact:conList){\nsmagicinteract__smsMagic__c smsObject = new smagicinteract__smsMagic__c();\nif(contact.MobilePhone != null){\nsmsObject.smagicinteract__SenderId__c = senderId;\nsmsObject.smagicinteract__PhoneNumber__c =contact.MobilePhone;\nsmsObject.smagicinteract__Name__c =contact.Name;\nsmsObject.smagicinteract__ObjectType__c = 'Contact';\nsmsObject.smagicinteract__disableSMSOnTrigger__c =0;\nsmsObject.smagicinteract__external_field__c =\nsmagicinteract.ApexAPI.generateUniqueKey();\nsmsObject.smagicinteract__SMSText__c = templateText;\nsmsObjectList.add(smsObject);\n}\n}\nDatabase.insert(smsObjectList,false);\n<\/pre>\n\n\n\n<p><strong>Limitation<\/strong><br>The maximum size of a callout request or response is 3 MB.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The purpose of this API resource is to send SMS messages in bulk. It does not create records of smsMagicObject inside your Salesforce organization. The Apex API class contains a\u00a0pushSMSCallout()\u00a0static method, which accepts the list of objects in\u00a0smagicinteract__smsMagic__c\u00a0and returns a text response. You can use this API resource as follows: String responseText = smagicinteract.ApexAPI.pushSMSCallout(smsObjectList); There [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"lsvr_kba_cat":[153],"lsvr_kba_tag":[],"class_list":["post-1397","lsvr_kba","type-lsvr_kba","status-publish","format-standard","hentry","lsvr_kba_cat-sms-magic-for-developers"],"_links":{"self":[{"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/lsvr_kba\/1397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/lsvr_kba"}],"about":[{"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/types\/lsvr_kba"}],"author":[{"embeddable":true,"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/comments?post=1397"}],"version-history":[{"count":1,"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/lsvr_kba\/1397\/revisions"}],"predecessor-version":[{"id":1398,"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/lsvr_kba\/1397\/revisions\/1398"}],"wp:attachment":[{"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/media?parent=1397"}],"wp:term":[{"taxonomy":"lsvr_kba_cat","embeddable":true,"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/lsvr_kba_cat?post=1397"},{"taxonomy":"lsvr_kba_tag","embeddable":true,"href":"https:\/\/staging.txtbox.in\/docs\/developers\/wp-json\/wp\/v2\/lsvr_kba_tag?post=1397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}