• Hareesh 2
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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">
<html>
<head>
<title>{!$Label.IC_GenerateSMS}</title> 
<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, '')}"/>

<script>
    $j = jQuery.noConflict();
    var backUrl = '/apex/IC_ClientDetails?id={!accountId}';
    
    function logTask(subject) {
        console.log('Selected Template ' + subject);
        IC_GenerateSMS_VFCx.createTask('{!accountId}','{!Email}',subject,
                                          function(records, e) {console.log(records);}, {escape:true});
    }
    
    function createMail(){
        
        logTask(document.getElementById("initSubject").innerHTML);
        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;
    }
</script>    
</head>
<body>
    <!-- EMAIL TEMPLATE PREVIEW AND SELECTION -->
    <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>
            <h1>{!$Label.IC_ChooseTemplate}</h1>
        </div>
        <!-- CONTENT -->
    <div data-role="content" data-fullscreen="true">   
       <ul data-role="listview" data-theme="a"  data-inset="true" >
           <li>
           <div>
            <!-- SMS TEMPLATE SELECTION FORM -->
            <apex:form >
             <!-- SMS TEMPLATE SELECTION LIST -->
             <center>
             <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"/>
                </apex:selectList>
             </div>  
             </center> 
                <!-- SMS TEMPLATE SELECTION PREVIEW -->
                <apex:outputpanel id="counter">
                    <!-- SMS TEMPLATE ENCODED FOR BROWSER PREVIEW -->          
                    <!-- <div id="Email">{!Email}</div>  -->
                    <br/>
                    <div id="Subject"></div>
                    <br/>
                    <div id="Body"></div>
                    <!-- SMS TEMPLATE ENCODED FOR MOBILE MAIL SYSTEM -->
                    <div id="initSubject" style="display:none;visbility:hidden;">{!initSubject}</div> 
                    <div id="initBody" style="display:none;visbility:hidden;">{!initBody}</div> 
                    <script>
                        document.getElementById("Subject").innerHTML = "{!Subject}";
                        document.getElementById("Body").innerHTML = "{!Body}";
                    </script>      
                </apex:outputpanel>
            </apex:form>
            <br/>
            <!-- BUTTON TO GENERATE SMS IN MOBILE MAIL SYSTEM -->
            <a data-role="button" data-direction="reverse" data-transition="none" href="javascript:createMail();" data-icon="false" data-iconpos="left">
                {!$Label.IC_GenerateSMS}
            </a>
            </div>
          </li>
          </ul>
        </div>
    </div>
</body>
</html>
</apex:page>


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);
        }else{
            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
    **/
    @RemoteAction
    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 !!