Set-up Send SMS Buttons

May 19, 2014
admin

How to Configure Buttons?

Contents
Understanding SMS Buttons

SMS Magic provides you the option to send SMS from page layouts (individual object records), search layouts (send bulk SMS to a list of object records) and from Campaigns (send bulk SMS to campaign members). The basic requirement for setting up Send SMS functionality on any object is that the object record should have a mobile number. If the mobile number is present in the related object, we can pull the mobile number with help of a formula field. For e.g.: We need to set up Send SMS on Opportunity and the mobile number is present in Accounts, we can create a formula field on the Opportunity object which will pull up the mobile number from the Accounts object. There are two interfaces available for sending SMS from page/search layouts – Visualforce page (available on page layouts, search layouts, campaign layout) or Pop Up (not available on Campaigns). This option can be configured by adding a parameter in the button code. The detailed steps on setting up Send SMS buttons are explained in their respective sections.

1. Pop up (not available on Campaigns)
Send-SMS-Pop-up
2. Visualforce page (available on page layouts, search layouts, campaign layout)
Send-SMS-VF-page
How to Configure “Send SMS“ and “Send bulk SMS“ Buttons for Leads & Contacts?

Send SMS buttons are pre-configured for the Standard Objects (Leads & Contacts), you just have to add them to the page layouts. These buttons use the standard mobile phone field to send SMS. In case you need to use any other field for sending SMS, you have to create new buttons.

To add the “Send SMS” button to the page layout of a standard object (in this case Leads), follow the steps listed below.

1. Go to App Setup–> Customize–> Leads–> Page Layout Click on “Edit” of the page layout to which you want to add the “Send SMS” button.   2. Go to “Buttons” tab from the page layout menu above Drag and drop the “Send SMS” button from the “Buttons” tab in the space for “Custom Buttons”.

add-send-SMS-to-page-layout1
3. Click on “Save” You can view the “Send SMS” button on the page layout of any lead record.

To add the “Send Bulk SMS” button to the search layout of a standard object (in this case Leads), follow the steps listed below.

1. Go to App Setup–> Customize–> Leads–> Search Layout Click on “Edit” of the page layout to which you want to add the “Send Bulk SMS” button.   2. Go to “Custom Buttons” Select “Send Bulk SMS” button under the Available Buttons and click on “Add” to add it to theSelected Buttons list.

Adding-Send-Bulk-SMS-to-search-layout
3. Click on “Save” You can view the “Send Bulk SMS” button on the search layout of the Lead object.
How to Configure “Send SMS”/ “Send Bulk SMS” buttons for Leads & Contacts to send SMS from a Custom Field (other than Mobile Number Field)?
You can send a SMS even if the mobile numbers are stored in a field other than the “Mobile” number field (e.g.: the “Phone” field) in the Leads or Contacts object. For this, we must create a “Send SMS”/ “Send Bulk SMS” button that will fetch the mobile number from the custom field before sending the SMS. Here we will see how to create these buttons for the Leads object.  

“Send SMS” button for mobile number stored in the custom field “Phone” on the Contacts object.

  Normally to create a button that will fetch the mobile number from a custom field, we only need to make a small change in the button code. But the “Send SMS” & “Send Bulk SMS” buttons are already configured for standard objects and their codes cannot be edited. For this reason we have to create a new button. Here, we will see how to create a “Send SMS from Phone” button for the Leads object. 1. Go to Setup–> Customize –> Contact–> Buttons & Links 2. Click on “New” under the label “Custom Buttons and Links”

sendfrmphonecontact2.1

Fill required data Such as Label, Name etc. (Though you can keep the label as “Send SMS”, we suggest you give this new button a unique Label such as “Send SMS from Phone”)

  • Select the Display type as “Detail Page Button”.
  •  Behavior as “Execute JavaScript”.
  • Select the content Source as “OnClick JavaScript”
phone
4. Copy & paste the code for “Send SMS” button from the window below. For this button to fetch the mobile number from a custom field (in this case “Phone”) ensure that :- the parameter mobileField = ‘Custom Field Name’;   The code for a “Send SMS” button is given below :
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} 
{!REQUIRESCRIPT('/resource/smagicinteract__smJQuery/js/jquery-1.10.2.js')} 
{!REQUIRESCRIPT('/resource/smagicinteract__smJQuery/js/jquery-ui-1.10.4.custom.min.js')} 
{!REQUIRESCRIPT("/resource/smagicinteract__sendSMSJS")}

var packagePrefix = "smagicinteract__"; 
var recordType = 'contact'; 
var idToUpdate = '{!Contact.Id}' 
var nameField = 'Name'; 
var mobileField = 'Phone'; 
var optOutField = 'smagicinteract__SMSOptOut__c'; 
var optOutDefaultValue = 'yes';
var smsType = ''; 
var userId = '{!$User.Id}'; 
var elementIdVar = ''; 
var showUserDropDown = false; 
var dialogTitle = ''; 
var cssUrl = '{!URLFOR('/resource/smagicinteract__smJQuery/css/sm-theme/jquery-ui-1.10.4.custom.min.css')}'; 

sendSMS(recordType, idToUpdate, userId, nameField, mobileField, optOutField, optOutDefaultValue, smsType, elementIdVar, packagePrefix, showUserDropDown, dialogTitle, cssUrl);
5. Click on “Check Syntax”. A message “No syntax error in merge fields or functions ” will be displayed. 6. Click on “Save”. Your “Send SMS from Phone” button is now created. 7. Add the newly created button to the “Page Layout“.

  • Go to App Setup–> Customize–> Leads–> Page Layout–> Edit–> Buttons.
  • Drag and drop the “Send SMS from Phone” button to the custom buttons area and click “Save”.

 

 “Send Bulk SMS” button for mobile number stored in the custom field “Phone” on the Leads object.

  Similar to creating “Send SMS from Phone” button, we can create a “Send Bulk SMS from Phone” button. The only difference will be -

  • The Display type should be “List Button”
  • The created button will have to be added to the “Search Layout“

Ensure that the parameter mobileField = ‘Custom Field Name’;   The code for a “Send Bulk SMS” button is given below:

leads

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} 

function loadJqueryDynamically(){

	var newscript = document.createElement('script'); 
	newscript.type = 'text/javascript'; 
	newscript.async = false; 
	newscript.src = '{!URLFOR('/resource/smagicinteract__smJQuery/js/jquery-1.10.2.js')}'; 
	(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(newscript); 

	var newscript1 = document.createElement('script'); 
	newscript1.type = 'text/javascript'; 
	newscript1.async = false; 
	newscript1.src = '{!URLFOR('/resource/smagicinteract__smJQuery/js/jquery-ui-1.10.4.custom.min.js')} '; 
	(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(newscript1); 

	var newscript2 = document.createElement('script'); 
	newscript2.type = 'text/javascript'; 
	newscript2.async = false; 
	newscript2.src = '{!URLFOR('/resource/smagicinteract__sendSMSJS')}'; 
	(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(newscript2); 
	newscript2.onload = showPage; 

}

loadJqueryDynamically(); 

function showPage() {

	var records = {!GETRECORDIDS($ObjectType.Contact)}; 
	if (records[0] == null){ 
		alert("Please select at least one contact.") 
	} 
	else{ 
		var packagePrefix = "smagicinteract__"; 
		var recordType = "Contact"; 
		var recordIds = ""; 
		var nameField = 'Name'; 
		var mobileField = 'Phone'; 
		var optOutField = 'smagicinteract__SMSOptOut__c'; 
		var optOutDefaultValue = 'yes'; 
		var smsType = ''; 
		var userId = '{!$User.Id}'; 
		var elementIdVar = ''; 
		var showUserDropDown = false; 
		var dialogTitle = ''; 
		var queryString = ''; 

		for (var n in records) { 
		if(n == 'remove' || n == 'indexOf') continue; 
		recordIds = recordIds + records[n]; 

		if (n != records.length-1) { 
		recordIds = recordIds + ","; 
		} 
		} 

		var cssUrl = '{!URLFOR('/resource/smagicinteract__smJQuery/css/sm-theme/jquery-ui-1.10.4.custom.min.css')}'; 

		if({!$Permission.smagicinteract__AllowToSendBulkMessage}) { 
		sendSMS(recordType, recordIds, userId, nameField, mobileField, optOutField, optOutDefaultValue, smsType, elementIdVar, packagePrefix, showUserDropDown, dialogTitle, cssUrl); 
		} 
		else { 
		alert('You cannot Send SMS. Please contact system admin'); 
		}

	}

}
/*
Details of parameters which can be modified :
recordType - include the object API name.
mobileField - use the field name which contain mobile phone of the record.
optOutField - use the field which contains opt out preference of the record.
smsType - this parameter can be used to sepcify the type of interface required. For Visualforce page, it should be left blank. For popup, its value should be 'popup'.
dialogTitle - you can mention the name of pop up dialogue box in this parameter.
*/
How to Configure “Send SMS” Button for Custom Objects?
The “Send SMS” button requires a mobile number field to send SMS. The field in which mobile number is present can be used in the button code.  

Step 1: Create “Send SMS” Button for a Custom Object

  In the example below, we will configure a “Send SMS” button on the Accounts object. 1. Go to Setup–> Customize –> (object name)–> Buttons & Links. 2. Click on “New” under the label “Custom Buttons and Links”.

custom-button-creation
3. Fill required data Such as label, Name etc.

  • Select the Display type as “Detail Page Button”.
  •  Behaviour as “Execute JavaScript”.
  • Select the content Source as “OnClick JavaScript”.
send sms - custom obj
4. Copy & paste the code for “Send SMS” button (through Pop up)from the window below.

Code for “Send SMS” button (through Pop up)
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} 
{!REQUIRESCRIPT('/resource/smagicinteract__smJQuery/js/jquery-1.10.2.js')} 
{!REQUIRESCRIPT('/resource/smagicinteract__smJQuery/js/jquery-ui-1.10.4.custom.min.js')} 
{!REQUIRESCRIPT("/resource/smagicinteract__sendSMSJS")} 

var packagePrefix = "smagicinteract__"; 
var recordType = 'Account'; 
var idToUpdate = '{!Account.Id}'; 
var nameField = 'Name'; 
var mobileField = 'Phone'; 
var optOutField = 'popup'; 
var optOutDefaultValue = 'no'; 
var smsType = ''; // for pop up, use value -'popup' 
var userId = '{!$User.Id}'; 
var elementIdVar = ''; 
var showUserDropDown = false; 
var dialogTitle = ''; 
var cssUrl = '{!URLFOR('/resource/smagicinteract__smJQuery/css/sm-theme/jquery-ui-1.10.4.custom.min.css')}'; 

sendSMS(recordType, idToUpdate, userId, nameField, mobileField, optOutField, optOutDefaultValue, smsType, elementIdVar, packagePrefix, showUserDropDown, dialogTitle, cssUrl); 

/* 

Details of parameters which can be modified : 
recordType - include the object API name. 
idToUpdate - include the object ID of the object used. 
mobileField - use the field name which contain mobile phone of the record. 
optOutField - use the field which contains opt out preference of the record. 
smsType - this parameter can be used to sepcify the type of interface required. For Visualforce page, it should be left blank. For popup, its value should be 'popup'. 
dialogTitle - you can mention the name of pop up dialogue box in this parameter. 
optOutDefaultValue = use this field to set the default value of opt out 
*/
You can change the parameter ‘smsType’ to toggle between Visualforce page or popup interface. If you wish to use a VF page, use a blank value for this parameter.  Use the parameter ‘optOutDefaultValue’  to set the default value of opt out. The default value will be reflected in the dropdown component on the visualforce page or on the popup . 5. Click on “Check Syntax”. A message “No syntax error in merge fields or functions ” will be displayed. 6. Click on “Save”. Your “Send SMS” button is now created.  

Step 2: Adding buttons to Page Layouts

  The Send SMS button created in Step 1 has to be added to the page layout of the objects. 1. Go to Setup –> Customize–> Accounts–> Page Layout –> Edit –> Buttons 2. Drag and drop the “Send SMS” button to the custom buttons area and click save.

add-send-SMS-to-page-layout1 (1)
The “Send SMS” button is ready to be used on the “Accounts” records!
How to Configure “Send Bulk SMS” button for Custom Objects?
“Send Bulk SMS” button requires a mobile number field to send SMS. The field in which mobile number is present can be specified in the button code.

Step 1: Create a “Send Bulk SMS” button for a custom object.

  In the example below, we will configure a “Send Bulk SMS” button on the Accounts object. 1. Go to Setup–> Customize –> Account (object name)–> Buttons & Links. 2. Click on “New” under the label “Custom Buttons and Links”.

custom-button-creation (1)
3. Fill required data Such as label, Name etc.

    • Select the Display type as “List Button”.

 

  •  Behaviour as “Execute JavaScript”.

 

 

  • Select the content Source as “OnClick JavaScript”.

 

 

custom-object
Code for Send Bulk SMS button (through Pop up)
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} 

function loadJqueryDynamically(){

	var newscript = document.createElement('script'); 
	newscript.type = 'text/javascript'; 
	newscript.async = false; 
	newscript.src = '{!URLFOR('/resource/smagicinteract__smJQuery/js/jquery-1.10.2.js')}'; 
	(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(newscript); 

	var newscript1 = document.createElement('script'); 
	newscript1.type = 'text/javascript'; 
	newscript1.async = false; 
	newscript1.src = '{!URLFOR('/resource/smagicinteract__smJQuery/js/jquery-ui-1.10.4.custom.min.js')} '; 
	(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(newscript1); 

	var newscript2 = document.createElement('script'); 
	newscript2.type = 'text/javascript'; 
	newscript2.async = false; 
	newscript2.src = '{!URLFOR('/resource/smagicinteract__sendSMSJS')}'; 
	(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(newscript2); 
	newscript2.onload = showPage; 

} 

loadJqueryDynamically(); 

function showPage(){

	var records = {!GETRECORDIDS($ObjectType.Account)}; 
	if (records[0] == null){ 
		alert("Please select at least one account.") 
	}
	else{
		var packagePrefix = "smagicinteract__"; 
		var recordType = "Account"; 
		var recordIds = ""; 
		var nameField = 'Name'; 
		var mobileField = 'Phone'; 
		var optOutField = ''; 
		var optOutDefaultValue = 'yes'; 
		var smsType = 'popup'; 
		var userId = '{!$User.Id}'; 
		var elementIdVar = ''; 
		var showUserDropDown = false; 
		var dialogTitle = ''; 
		var queryString = ''; 

		for (var n in records){
			if(n == 'remove' || n == 'indexOf') continue; 
			recordIds = recordIds + records[n]; 

			if (n != records.length-1){
				recordIds = recordIds + ","; 
			}
		}

		var cssUrl = '{!URLFOR('/resource/smagicinteract__smJQuery/css/sm-theme/jquery-ui-1.10.4.custom.min.css')}'; 

		if({!$Permission.smagicinteract__AllowToSendBulkMessage}){
			sendSMS(recordType, recordIds, userId, nameField, mobileField, optOutField, optOutDefaultValue, smsType, elementIdVar, packagePrefix, showUserDropDown, dialogTitle, cssUrl); 
		}
		else{
			alert('You cannot Send SMS. Please contact system admin'); 
		}

	}

}

You can change the parameter ‘smsType’ to toggle between Visualforce page or popup interface. If you wish to use a VF page, use a blank value for this parameter. For example var smsType = ‘ ‘;

Step 2: Adding the “Send Bulk SMS” button to Search Layouts

The “Send Bulk SMS” button created in Step 1 has to be added to the page layout of the objects. 1. Go to Setup –> Customize–> Accounts–> Search Layout –> List View–>Edit

Seach-Layout-on-Account
2. Add it to the search layout and click on “Save”.
Adding-Send-Bulk-SMS-to-search-layout (1)
The “Send Bulk SMS” button is ready to be used on Account records!
How to Configure “Send SMS”/ “Send Bulk SMS” buttons for Custom Objects (Objects other than Leads & Contacts) to send SMS from a Custom Field (other than Mobile Number Field)?
You can send a SMS even if the mobile numbers are stored in a field other than the “Mobile” number field (e.g.: the “Phone” field) in any object. In case of custom objects, we can create a “Send SMS”/ “Send Bulk SMS” button that will fetch the mobile number from the custom field before sending the SMS in two ways

  • Edit the existing button code.
  • Create a new button.

In the following example, let us see how to create buttons for mobile numbers stored in the custom field “Phone” for custom object “Accounts”.  

1. “Send SMS”/ “Send Bulk SMS” button for mobile number stored in the custom field “Phone” on the custom object “Accounts” by editing the existing button code.

For a button that will fetch the mobile number from a custom field, we only need to make a small change in the button code. In the button code for “Send SMS” and “Send Bulk SMS” buttons, the parameter “mobileField” defines the destination of the mobile number. Hence, ensure that this parameter is set to the custom field name from where the mobile number is to be fetched. E.g.: If the mobile number is stored in the “Phone” field, then mobileField = ‘Phone’;    

2. Create new “Send SMS”/ “Send Bulk SMS” button for mobile number stored in the custom field “Phone” on the custom object “Accounts “

You can also create a new “Send SMS from Custom Field”/ “Send Bulk SMS from Custom Field” button. To see how to create a new “Send SMS from Custom Field” button, please refer to “Send SMS Button for Custom Objects” above. While creating a new button, please ensure that-

  • The parameter mobileField = ‘Custom Field Name’; in the button code.
  • The newly created “Send SMS from Custom Field” button is added to the “Page Layout“.

To see how to create a new “Send Bulk SMS from Custom Field” button, please refer to “Send Bulk SMS Button for Custom Objects” above. While creating a new button, please ensure that-

  • The parameter mobileField = ‘Custom Field Name’; in the button code.
  • The newly created ”Send Bulk SMS from Custom Field” button is added to the “Search Layout“.
How to Configure “Run SMS Campaign” button on Campaigns?
With Campaigns, we can send a SMS to upto 500,000 records as against the “Send Bulk SMS” option that allows SMS to be sent to only 200 records at a time.

To send SMS from Campaign:-

1. Create Campaign (Salesforce Standard) & add members to it (Only Leads and Contacts can be added as members) 2. Configure “Run SMS Campaign” button on Campaign Object. To Configure the “run SMS Campaign” button, go to the  Setup–> Customize–> Campaigns–> Page Layout–> Edit. Go to buttons and drag & drop the Run SMS Campaign button in the space provided for custom buttons.

add-sms-to-campaigns
3. To add SMS History related list, go to the Setup–> Customize–> Campaigns–> Page Layout–> Edit. Add (drag & drop) smsMagic related list to the page layout and click “Save”.
add-sms-magic-related-list-to-campaign
4. Select a campaign and click  on the “Run SMS Campaign” button to send SMS to all members.
Campaign Send SMS page
5. Once you click on the “Run SMS Campaign”  button,  you have option to select a template for Contacts ( refer step 1) and  for Leads ( refer step 2 ) separately. Select the appropriate template. 6. You need to select status of Campaign members (Leads & Contacts) to whom you are willing to send SMS to filter the records.(This step is mandatory). 7. Click on the “Run Campaign” button, and SMS will get sent to all above selected members.
How to Configure a “Run SMS Campaign from Custom Field” button on Campaigns?
You can configure a “Run SMS Campaign” button that will send SMS to mobile numbers saved in custom fields like “Phone” or “Alternate Mobile Number”. For this, we need to create a new button “Run SMS Campaign from Custom Field”. In the example below, we will see how to create a button that will send SMS to the mobile numbers stored in the custom field “Phone” from the Campaigns object. 1. To create a new button, go to Setup–> Customize–> Campaigns–> Buttons, Links & Actions. Click on “New Button or Link”
campaignfrmcustomobj1.1
2. Add the button details like Label, Name etc.

  • Select the Display type as “Detail Page Button”.
  •  Behavior as “Execute JavaScript”.
  • Select the content Source as “OnClick JavaScript”.

  3. Copy & paste the code given below.

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

var packagePrefix = "smagicinteract__";
var recordType = "campaignmember";
var idToUpdate = "{! Campaign.Id }";
var leadPhoneField = "MobilePhone";
var contactPhoneField = "MobilePhone";
var optOutDefaultValue = 'no';

if({!$Permission.smagicinteract__AllowToSendCampaignMessage}) {
	var queryString = parent.window.location.pathname;
	if (parent.window.location.search){
		queryString = queryString + parent.window.location.search
	}
	var url = "/apex/"+packagePrefix+"CampaignSMSSendPage?retURL="+queryString + "&objectType="+recordType+"&recordIds="+idToUpdate+"&optOutDefaultValue="+ optOutDefaultValue+"&leadPhoneField="+leadPhoneField+"&contactPhoneField="+contactPhoneField ;

	parent.window.location = url;
}
else{
	alert('You cannot Run SMS Campaign. Please contact system admin'); 
}
Run SMS Campaign
The parameters leadPhoneField and contactPhoneField define the destination of the stored mobile numbers to which a SMS is to be sent. Hence, ensure that these parameters are set to the custom field from where the mobile numbers are to be fetched. i.e.:  leadPhoneField = “Phone”; and contactPhoneField = “Phone”; (where “Phone” is the custom field)   Check syntax for errors. When a message “No errors in the merge fields or functions” is displayed, click on “Save”. You button is now created. 4. Add the newly created button to the “Page Layout“.

  • Go to App Setup–> Customize–> Campaign–> Page Layout–> Edit–> Buttons.
  • Drag and drop the “Run Campaign from Telephone” button to the custom buttons area.
campaignfrmcustomobj3.1
Click on “Save”.
Send SMS to upto 3 phone number fields using send SMS button
SMS Magic Interact (Jun’15) allows user to send SMS up to 3 phone numbers using send SMS button.

If you select multiple fields, every number will receive a SMS and respective credits will be deducted.

Screenshot_3

 

You can try following code:-

1. Go to Setup

2. Customize -> Buttons, links and action

3. Click on send SMS Script.

4. Change ‘var mobileField’= ‘MobilePhone,Phone,Fax’

b

Related Posts

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>