+ Start a Discussion
yazid akki 15yazid akki 15 

SMS template Help !!

Hi everybody,

I have a mobile application Salesforce, in the user details's page, there is an SMS boutton, when I click on, I have to choose a template (Text body) and click Send .
The button have to send me to my mobile' SMS section with the choosed the template.
I'm stuck in the last step . How can i get from a mobile salesforce to SMS section ?

It works great with email and seletion templates too. So I just changed some paramettres as [Email = account.PersonEmail ;] by [Email = account.PersonMobilePhone ;]

VF page IC_GenerateSMS

<apex:page showHeader="false" docType="html-5.0" standardStylesheets="false" cache="false" Controller="IC_GenerateSMS_VFCx">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

<link rel="stylesheet" href="{!URLFOR($Resource.JQuery_120, 'jquery.mobile-1.2.0.min.css')}" />
<apex:includeScript value="{!URLFOR($Resource.JQuery_120, 'jquery-1.8.2.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.JQuery_120, 'jquery.mobile-1.2.0.min.js')}"/>   

<!-- New Relic integration -->
<apex:includeScript value="{!IF($Setup.ICONSettings__c.NewRelic__c, $Resource.NewRelic, '')}"/>

    $j = jQuery.noConflict();
    var backUrl = '/apex/IC_ClientDetails?id={!accountId}';
    function logTask(subject) {
        console.log('Selected Template ' + subject);
                                          function(records, e) {console.log(records);}, {escape:true});
    function createMail(){
        var email = document.getElementById("Email").innerHTML;
        var subject = encodeURIComponent(document.getElementById("initSubject").innerHTML);
        var body = encodeURIComponent(document.getElementById("initBody").innerHTML);
        window.location = "mailto:"+email+"?subject="+subject+"&body="+body;
    <div data-role="page" data-theme="a" id="mainpage" data-fullscreen="true" data-add-back-btn="true">
        <!-- HEADER -->
        <div data-role="header">
            <a href="#" onclick="window.location.href=backUrl;" data-icon='arrow-l' style="box-shadow: none;" data-iconshadow="false" data-iconpos="notext"></a>
        <!-- CONTENT -->
    <div data-role="content" data-fullscreen="true">   
       <ul data-role="listview" data-theme="a"  data-inset="true" >
            <!-- SMS TEMPLATE SELECTION FORM -->
            <apex:form >
             <!-- SMS TEMPLATE SELECTION LIST -->
             <div data-role="fieldcontain">
                <label for="selectedTemplate">{!$Label.IC_SelectTemplate}</label>   
                <apex:selectList value="{!selectedTemplate}"  size="1" id="selectedTemplate">
                    <apex:selectOptions value="{!templateOptions}"/>
                    <apex:actionSupport event="onchange" action="{!previewTemplate}" rerender="counter"/>
                <!-- SMS TEMPLATE SELECTION PREVIEW -->
                <apex:outputpanel id="counter">
                    <!-- SMS TEMPLATE ENCODED FOR BROWSER PREVIEW -->          
                    <!-- <div id="Email">{!Email}</div>  -->
                    <div id="Subject"></div>
                    <div id="Body"></div>
                    <div id="initSubject" style="display:none;visbility:hidden;">{!initSubject}</div> 
                    <div id="initBody" style="display:none;visbility:hidden;">{!initBody}</div> 
                        document.getElementById("Subject").innerHTML = "{!Subject}";
                        document.getElementById("Body").innerHTML = "{!Body}";
            <a data-role="button" data-direction="reverse" data-transition="none" href="javascript:createMail();" data-icon="false" data-iconpos="left">

IC_GenerateSMS_VFCx Controller

public with sharing class IC_GenerateSMS_VFCx {
 /** Variable declarations **/
    public String accountId{get;set;}
    public String ownerId;
    private Account account;
    private User owner;
    private User Sender;
    //public String SMS{get;set;}
    public String Email{get;set;}
    public String Subject{get;set;}
    public String initBody{get;set;}
    public String initSubject{get;set;}
    public String Body{get;set;}
    private List<EmailTemplate> emailtemplates;
    private List<SelectOption> tempList = new List<SelectOption>();
    private EmailTemplate emailTemplate;
    public string selectedTemplate{get;set;}
    public IC_GenerateSMS_VFCx() {
        /** Retrieve sms templates dedicated to mobile device **/
        List<Folder> Folders = [Select Id, Name From Folder Where Type = 'Email' AND DeveloperName like  '%Mobile'];
        emailtemplates = [select Id,Name,Subject,body,IsActive from EmailTemplate Where Folder.Id IN :Folders AND IsActive = true  Order By Folder.Name, Name Limit 1 ];
        tempList.add(new SelectOption('NONE', '----- ' + Label.IC_None +' -----'));
        for (EmailTemplate emailTemp : emailtemplates) {
            tempList.add(new SelectOption(emailTemp.id, emailTemp.Name));
        /** Retrieve current account and owner information **/
        accountId = ApexPages.currentPage().getParameters().get('id');
        //account = [select id, Salutation, FirstName, LastName, PersonEmail, OwnerId from Account where id =: accountId];
        account = IC_Factory.getAccountt(accountId);
        //Email = account.PersonEmail;
        Email = account.PersonMobilePhone;
        //owner = [select id, FirstName, LastName from User where id = :account.OwnerId];
        //Sender = [select id, defaultStore__c from User where id =: UserInfo.getUserId()];
        owner = IC_Factory.getUser(account.OwnerId);
        Sender = IC_Factory.getUser(userInfo.getUserId());
    /** Provide options for email template list **/
    public List<SelectOption> getTemplateOptions() {
        return tempList;
    /** Encode and provide email template content **/
    public PageReference previewTemplate(){
        if(selectedTemplate <> 'NONE'){
            emailTemplate = [select Id,Name,Subject,Body from EmailTemplate where Id =: selectedTemplate LIMIT 1];
            Subject = renderMergeFieldsAndReplaceEncoding(emailTemplate.Subject);
            Body = renderMergeFieldsAndReplaceEncoding(emailTemplate.Body);
            initSubject = renderMergeFields(emailTemplate.Subject);
            initBody = renderMergeFields(emailTemplate.Body);
            Subject = '';
            Body = '';
            initSubject = '';
            initBody = '';
        return null;
    private String nullToText(String value) {
        return (value == null?'':value);
    private String nullToText_Title(String value) {
        return IC_UTILS.getTranslationPicklistValue('Contact', 'Salutation', value);
    private String nullToText_Salutation(String value) {
        return IC_UTILS.getTranslationPicklistValue('Contact', 'Salutation', value);
    /** Replace dynamic fields by value **/
    private String renderMergeFields(String textToRender) {
        textToRender = textToRender.replace('{!Contact.Salutation}', account.Title__pc == null ? nullToText_Salutation(account.Salutation):nullToText_Title(account.Title__pc) );
        textToRender = textToRender.replace('{!Contact.FirstName}',  nullToText(account.FirstName));
        textToRender = textToRender.replace('{!Contact.LastName}',  nullToText(account.LastName));
        textToRender = textToRender.replace('{!Contact.OwnerFirstName}',  nullToText(owner.FirstName));
        textToRender = textToRender.replace('{!Contact.OwnerLastName}',  nullToText(owner.LastName));
        textToRender = textToRender.replace('{!User.FirstName}',  nullToText(UserInfo.getFirstName()));
        textToRender = textToRender.replace('{!User.LastName}',  nullToText(UserInfo.getLastName()));
        textToRender = textToRender.replace('{!User.DefaultStore__c}', nullToText(Sender.defaultStore__c));
        return textToRender;
    /** Replace dynamic fields by value and formate for brower display **/
    private String renderMergeFieldsAndReplaceEncoding(String textToRender) {
        textToRender = textToRender.replace('{!Contact.Salutation}', account.Salutation);
        textToRender = textToRender.replace('{!Contact.FirstName}', account.FirstName);
        textToRender = textToRender.replace('{!Contact.LastName}', account.LastName);
        textToRender = textToRender.replace('{!Contact.OwnerFirstName}', owner.FirstName);
        textToRender = textToRender.replace('{!Contact.OwnerLastName}', owner.LastName);
        textToRender = textToRender.replace('{!User.FirstName}', UserInfo.getFirstName());
        textToRender = textToRender.replace('{!User.LastName}', UserInfo.getLastName());
        textToRender = textToRender.replace('{!User.DefaultStore__c}', Sender.defaultStore__c);
        textToRender = renderMergeFields(textToRender);    
        textToRender = textToRender.replace('\\n', '<br/>');
        return textToRender;
    * Create new Task for current user and selected client when user click on SMS or Mobile
    public static String createTask(String accountId, String numberPhone, String selectedTemplate) {
        system.debug ('*** createTask ');
        String tskSubject = Label.IC_SendEmail + ': ' + selectedTemplate; 
        String tskDescription =  String.format(Label.IC_TaskDescriptionEmail, new String[] {String.valueOf(Date.toDay()), UserInfo.getName(),  numberPhone, selectedTemplate });       
        Task newTask = IC_Factory.createTask(accountId, tskSubject, tskDescription, null, null, null, null, 'Email');
        newTask.TECH_is_AutoSave__c = true;
        return IC_Factory.insertTask(newTask);

Help Please !!
ValueText SMSValueText SMS
In 3 ways you can send SMS from Salesforce.
In every option you have pros and cons and choose based on your criteria.

1. Salesforce default SMS sending
     A. Cost vise very expensive in case of messaging. 
     B.Some places you have to put your development efforts to make the process automatic.
2. Integrate SMS gateway.
    N number of gateways in a market where you can choose and integrate.

SMS prices are low.
If you want to send SMS to different countries Integration is not a good option because International SMS gateway can not give SMS at local Price.
You have to put your development efforts for dynamic message creation in triggers.     
You have to invest your money and time on every SMS template creation.
3. You can find App in AppExchange.
There are a few apps in AppExhnage which are providing complete automation.
No development efforts.
Like Email template you can create SMS template.
You can send SMS with workflow where you need not to write triggers.
If your option is 3 ? You can have a look at our ValueText SMS(https://appexchange.salesforce.com/listingDetail?listingId=a0N3A00000EFoedUAD) App (https://goo.gl/9B6B7d) at AppExchange.
Hareesh 2Hareesh 2
What is IC_Factory,IC_None,IC_UTILS ??