1

We have developed an custom email section to have the emails in sequential order when a case is cloned (as this functionality is not there with standard emails section).

Now we are facing a strange issue when ever case subject contains single quote(example=> test subject 'for case) and custom emails section button and link is not working. below is the custom email section UI enter image description here

Here the send email button and subject links are not working when the case subject contains quote but reply and to all links are still working. Below is the vf page code:

<apex:page standardController="Case" sidebar="false" showHeader="false" applyHtmlTag="false" extensions="sortEmailMessage">
<apex:includeScript value="/support/console/45.0/integration.js"/>
<apex:form >
    <script>
    var subjectId;
    var statusForEmail;
    var salesforceSubTab;
    function sendpage()
    { 
        var pages = "/_ui/core/email/author/EmailAuthor?p2_lkid="+'{!ContactId}'+"&rtype="+'003'+"&p3_lkid="+'{!caseId}'+"&p24="+'{!home_email}'+"&p6="+'{!caseObj.subject}   Casenumber:{!caseObj.casenumber} '+"&retURL="+'{!caseId}';
        //window.open(pages,'_parent');
        if (sforce.console.isInConsole()) {
            sforce.console.getEnclosingPrimaryTabId(openSubtab12);
        }else{

            var pages = "/_ui/core/email/author/EmailAuthor?p2_lkid="+'{!caseObj.ContactId}'+"&rtype="+'003'+"&p3_lkid="+'{!caseId}'+"&p6="+'{!caseObj.subject}   {!caseObj.casenumber} '+"&retURL="+'{!caseId}';
            window.open(pages,'_parent');
        }
        //'salesforce', openSuccess, 'salesforceTab');
    }

    function sendpage2(emailId)
    { 
        var pages = "/"+emailId;
        //window.open(pages,'_parent');
        if (sforce.console.isInConsole()) {
            sforce.console.getEnclosingPrimaryTabId(openSubtab13);
        }else{

            var pages = "/"+emailId;
            window.open(pages,'_parent');
        }
        //'salesforce', openSuccess, 'salesforceTab');
    }
      function openDetailPage(emailid, Incoming)
    {
        console.log(Incoming);
        statusForEmail = Incoming;
        salesforceSubTab = emailid;
        //var pages= "/"+emailid;            
        //window.open(pages,'_parent');
        sendpage2(emailid);
        subjectId = emailid;
     }



    var openSubtab12 = function openSubtab12(result) {
        //Now that we have the primary tab ID, we can open a new subtab in it
        var primaryTabId = result.id;
        var pages = "/_ui/core/email/author/EmailAuthor?p3_lkid="+'{!caseId}'+"&p24="+'{!home_email}'+"&p6="+'{!caseObj.subject}   {!caseObj.casenumber}'+"&retURL="+'{!caseId}';
        sforce.console.openSubtab(primaryTabId , pages, true, 
                                  'Send an Email', null, openSuccess, 'salesforceSubtab');
    };


       var openSubtab13 = function openSubtab13(result) {
           console.log(result);
           // var pages = "/"+emailId;
           var emailmsg = '';
           var subTab13 = salesforceSubTab;
        //Now that we have the primary tab ID, we can open a new subtab in it
           if(statusForEmail == false)
               {
               emailmsg = 'Outbound Email Message'
               }
           if(statusForEmail == true)
               {
                emailmsg = 'Inbound Email Message'
                }
        var primaryTabId = result.id;
       var pages= "/"+subjectId;   
        sforce.console.openSubtab(primaryTabId, pages, true, 
                                  emailmsg , null, openSuccess, subTab13);
    };


    </script>
       <script type="text/javascript">
    var aMindSwitchContextSubtabId = null; // must be set at runtime by getFocusedSubtabId event
    function back2Case() {
        //First find the ID of the primary tab to put the new subtab in
        sforce.console.getEnclosingPrimaryTabId(openSubtab);
    }

    var openSubtab = function openSubtab(result) {
        //Now that we have the primary tab ID, we can open a new subtab in it
        var primaryTabId = result.id;            
    };

    var openSuccess = function openSuccess(result) {
        //Report whether we succeeded in opening the subtab
        if (result.success == true) {
            console.log('subtab successfully opened');
        } else {
            console.log('subtab cannot be opened');
        }
    };

    var aMindSwitchContextGetFocusedSubtabId = function( result ) {
        aMindSwitchContextSubtabId = result.id;
    };

    sforce.console.getFocusedSubtabId(aMindSwitchContextGetFocusedSubtabId);


        function callme(emailId)
        {   
             subjectId = emailId;

            //var pages = "/_ui/core/email/author/EmailAuthor?email_id="+emailId+"&replyToAll=0&retURL=/"+'{!caseId}';
            //window.open(pages,'_parent');
             if (sforce.console.isInConsole()) {
                 sforce.console.getEnclosingPrimaryTabId(openSubtab15);
             }else{

         var pages = "/_ui/core/email/author/EmailAuthor?email_id="+emailId+"&replyToAll=0&retURL=/"+'{!caseId}';
         window.open(pages,'_parent');
         }
        //'salesforce', openSuccess, 'salesforceTab');

        }
        function callmeToall(emailId)
        {   
             subjectId = emailId;

            //var pages = "/_ui/core/email/author/EmailAuthor?email_id="+emailId+"&replyToAll=1&retURL=/"+'{!caseId}';
            //window.open(pages,'_parent');
             if (sforce.console.isInConsole()) {
                 sforce.console.getEnclosingPrimaryTabId(openSubtab16);
             }else{

         var pages = "/_ui/core/email/author/EmailAuthor?email_id="+emailId+"&replyToAll=1&retURL=/"+'{!caseId}';
         window.open(pages,'_parent');
         }
        //'salesforce', openSuccess, 'salesforceTab');

        }
     var openSubtab16 = function openSubtab16(result) {
         console.log('entered to reply all url');

        //Now that we have the primary tab ID, we can open a new subtab in it
        var primaryTabId = result.id;

       var pages= "/_ui/core/email/author/EmailAuthor?email_id="+subjectId+"&replyToAll=1&retURL=/"+'{!caseId}';  
        sforce.console.openSubtab(primaryTabId , pages, true, 
                                  'Send an Email', null, openSuccess, 'subTab16');
    };

    var openSubtab15 = function openSubtab15(result) {

     console.log('entered to reply url');

        //Now that we have the primary tab ID, we can open a new subtab in it
        var primaryTabId = result.id;

       var pages= "/_ui/core/email/author/EmailAuthor?email_id="+subjectId+"&replyToAll=0&retURL=/"+'{!caseId}';  
        sforce.console.openSubtab(primaryTabId , pages, true, 
                                  'Send an Email', null, openSuccess, 'subTab15');
    };

    </script>
<apex:pageBlock >
    <apex:outputpanel layout="block" style="width:100%;">
        <table style="width:100%;">
            <tr style="width:100%;">
                <td style="margin-left:50px;">
                    <apex:commandbutton style="margin-left: 245px;" value="Send an Email" onclick="sendpage();" rerender="frm1"/>
                </td>
                <td style="width: 35%;">
                </td>
                <td> <span class="help" style="color: #015ba7;text-decoration: none;" title="Emails Help (New Window)"><a href="javascript:openPopupFocusEscapePounds(%27https://help.salesforce.com/apex/htdoor?loc=help&amp;target=cases_email.htm&amp;section=Cases&amp;language=en_US&amp;release=214.14.1&amp;instance=CS63&amp;showSplash=true%27, %27Help%27, 1024, 768, %27width=1024,height=768,resizable=yes,toolbar=yes,status=yes,scrollbars=yes,menubar=yes,directories=no,location=yes,dependant=no%27, false, false);" class="linkCol"><span style="color: #015ba7;text-decoration: none;" class="linkSpan">Emails Help</span> <img src="/img/s.gif" alt="Emails Help (New Window)" class="helpIcon" title="Emails Help (New Window)"/></a></span></td>
            </tr>
        </table>
    </apex:outputpanel>

<apex:pageBlockTable value="{!EmailMessages}" var="items" rendered="{!if(EmailMessages.size > 0,true,false)}">
    <apex:column headerValue="Action" style="width:80px">
       <apex:outputpanel > 
            <a herf="/{!items.id}" onclick="callme('{!items.id}');" style="cursor: pointer;color: #015ba7;font-weight: normal">Reply</a> &nbsp;|&nbsp;
           <a onclick="callmeToall('{!items.id}');" style="cursor: pointer;color: #015ba7;font-weight: normal">To All</a>
           <!-- <a target="_blank" href="https://aig--qa.cs14.my.salesforce.com/_ui/core/email/author/EmailAuthor?email_id={!items.id}&replyToAll=1&retURL={!caseId}">Del</a> -->
        </apex:outputpanel>
    </apex:column>
    <apex:column headerValue="Status">
        <apex:outputtext value="Read" rendered="{!if(items.status == '1',true,false)}"></apex:outputtext>
        <apex:outputtext value="Replied" rendered="{!if(items.status == '2',true,false)}"></apex:outputtext>
        <apex:outputtext value="Sent" rendered="{!if(items.status == '3',true,false)}"></apex:outputtext>
        <apex:outputtext value="New" rendered="{!if(items.status == '0',true,false)}"></apex:outputtext>
        <apex:outputtext value="Forwarded" rendered="{!if(items.status == '4',true,false)}"></apex:outputtext>
    </apex:column>
    <apex:column style="width: 40px;" >
    <!--<apex:outputPanel onclick="sendpage()"  rendered="{!if(items.status == '1',true,false)}">
        <img src="/img/emailInbound.gif" alt="Inbound" title="Inbound" height="13" width="16"/> &nbsp;<apex:outputpanel rendered="{!items.hasattachment}"><img src="/img/emailHasAttach.gif" alt="Has Attachment" title="Has Attachment" height="13" width="16"/></apex:outputpanel>
    </apex:outputPanel>
    <apex:outputPanel onclick="sendpage()"  rendered="{!if(items.status == '0',true,false)}">
        <img src="/img/emailInbound.gif" alt="Inbound" title="Inbound" height="13" width="16"/> &nbsp;<apex:outputpanel rendered="{!items.hasattachment}"><img src="/img/emailHasAttach.gif" alt="Has Attachment" title="Has Attachment" height="13" width="16"/></apex:outputpanel>
    </apex:outputPanel>
        <apex:outputPanel onclick="sendpage()" rendered="{!if(items.status == '2',true,false)}">
             <img src="/img/emailOutbound.gif" alt="Outbound" title="Outbound" height="13" width="16"/> &nbsp;<apex:outputpanel rendered="{!items.hasattachment}"><img src="/img/emailHasAttach.gif" alt="Has Attachment" title="Has Attachment" height="13" width="16"/></apex:outputpanel>
    </apex:outputPanel>
        <apex:outputPanel onclick="sendpage()" rendered="{!if(items.status == '3',true,false)}">
            <img src="/img/emailOutbound.gif" alt="Outbound" title="Outbound" height="13" width="16"/> &nbsp; <apex:outputpanel rendered="{!items.hasattachment}"><img src="/img/emailHasAttach.gif" alt="Has Attachment" title="Has Attachment" height="13" width="16"/></apex:outputpanel>
    </apex:outputPanel>-->
    <apex:outputPanel onclick="sendpage()"  rendered="{!if(items.Incoming,true,false)}">
        <img src="/img/emailInbound.gif" alt="Inbound" title="Inbound" height="13" width="16"/> &nbsp;<apex:outputpanel rendered="{!items.hasattachment}"><img src="/img/emailHasAttach.gif" alt="Has Attachment" title="Has Attachment" height="13" width="16"/></apex:outputpanel>
    </apex:outputPanel>
    <apex:outputPanel onclick="sendpage()" rendered="{!if(items.Incoming,false,true)}">
             <img src="/img/emailOutbound.gif" alt="Outbound" title="Outbound" height="13" width="16"/> &nbsp;<apex:outputpanel rendered="{!items.hasattachment}"><img src="/img/emailHasAttach.gif" alt="Has Attachment" title="Has Attachment" height="13" width="16"/></apex:outputpanel>
    </apex:outputPanel>

    </apex:column>
    <apex:column headerValue="Subject">
        <a herf="/{!items.id}" style="{!if(items.status == '0','cursor: pointer;font-weight: bold;','cursor: pointer;')}" onclick="openDetailPage('{!items.id}', '{!items.Incoming}')" > {!items.subject} </a>
        <!--<a herf="/{!items.id}" style="{!if(items.status == '0','cursor: pointer;font-weight: bold;','cursor: pointer;')}" > {!items.subject} </a>-->
        <!-- <apex:commandLink action="/{!items.id}" style="cursor: pointer;font-weight: bold;" rendered="{!if(items.status == '0',true,false)}" onclick="openDetailPage('{!items.id}', '{!items.Incoming}')" value="{!items.subject}"/>-->
         <!-- <apex:commandLink action="/{!items.id}" style="cursor: pointer;" rendered="{!if(items.status == '0',false,true)}"  onclick="openDetailPage('{!items.id}', '{!items.Incoming}')" value="{!items.subject}"/>-->

    </apex:column>
    <apex:column headerValue="Email Address">
        <apex:outputtext value="{!items.FromAddress}" rendered="{!if(items.Incoming,true,false)}"></apex:outputtext>
        <apex:outputtext value="{!items.ToAddress}" rendered="{!if(items.Incoming,false,true)}"></apex:outputtext>

        <!-- <apex:outputpanel onclick="sendpage()" >{!items.FromAddress} </apex:outputpanel>-->
    </apex:column>
    <apex:column headerValue="Message Date">
        <apex:outputField value="{!items.MessageDate}" /> 
        <!-- <apex:outputText value="{0,date,MM/dd/yy hh:mm a}"> <apex:param value="{!items.MessageDate}" /> </apex:outputText>-->

    </apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>

And controller class is below :

public class sortEmailMessage 
{
    public String caseId {get;set;}
    public case caseObj {get;set;}

    public String home_email {get;set;}
    public EmailMessage emailMessageID {get;set;}
    public String ContactId {get;set;}

    public sortEmailMessage(ApexPages.StandardController controller)
    {
        home_email = null;
        caseId= controller.getId();

        caseObj = [select Id,Subject,ContactId,Contact.Name,casenumber,Contact.Email,Contact.Home_Email__c,Contact.Employee_Status__c from case where Id=:caseId];
        /*if(caseObj.personal_email_address__c &&caseObj.ContactId!=null && (caseObj.contact.Employee_Status__c.contains('Terminated')|| caseObj.contact.Employee_Status__c.contains('Leave')))
        {
            if(caseobj.contact.email!=null && !caseobj.contact.email.contains('aig.com'))
                home_email = String.valueof(caseobj.contact.email);
             else if(caseobj.contact.Home_Email__c !=null)
                 home_email = String.valueof(caseobj.contact.Home_Email__c); 
            } */  
    }

    public List<EmailMessage> getEmailMessages()
    {        
        return [select Id,subject,
                            status,FromAddress,ToAddress,Incoming,TextBody,HTMLBody,hasAttachment,
                            MessageDate from EmailMessage 
                            where parentId =:caseId order by MessageDate desc];       
    }

   }

If i comment the below line from controller class then it is working.

caseObj = [select Id,Subject,ContactId,Contact.Name,casenumber,Contact.Email,Contact.Home_Email__c,Contact.Employee_Status__c from case where Id=:caseId];

Can you please help me where i am missing to find root cause of this issue.

4
  • you may need to use VF function JSENCODE(...)
    – cropredy
    May 1, 2019 at 16:03
  • I tried using JSENCODE(...), URLENCODE(case.Subject) but still it is not working, I am also trying to use string.escapesinglequotes() in my controller class. Can you please give me idea how i could use string.escapesinglequotes() in class where i am querying and assigning results to caseObj. May 2, 2019 at 8:36
  • Please use edit and strip out irrelevant portions of VF page and controller. See How to Ask. You'll get more help without so large a code dump.
    – cropredy
    May 2, 2019 at 13:18
  • Hey Cropredy, using JSENCODE(...), URLENCODE(case.Subject) are working, with little modification in the VF page. Thanks very much for the help !! May 3, 2019 at 6:42

1 Answer 1

3

Anywhere you merge a field into a url, use the URLENCODE function.

Instead of {!case.Subject}, use {!URLENCODE(case.Subject)}.

If that doesn't work, create a property on your controller which quote wraps the subject. There are many valid syntax options but here is one:

public String getQuoteWrappedSubject()
{
    return (case == null) ? null : '"' + case.Subject + '"'. 
}

Then in your markup you would change {!case.Subject} to {!URLENCODE(quoteWrappedSubject)}.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .