Friday, 5 August 2016

Salesforce Header and Sidebar is not displaying in visualforce Page

To resolve this issue, if you see inline=1 in the URL of the visualforce page, then that is the reason for the header and sidebar is not displayed.

To  resolve this issue, please use this below script in the visualforce page to display the sidebar and header.

<script>

if (location.href.match(/inline=1/)) window.top.location=location.href.replace(/inline=1/, '');
</script>

Monday, 1 August 2016

Add LiveChat User Information into Live Chat Transcript Object using Deployment API

As we all know we can get the custom detail of the users/visitors who clicks the live chat icon in the website. In salesforce the details of the users/visitors will be available for the Agent in the visitor detail page but, when you are trying to pull the reports for that data which resides in the Visitor detail page, it is not possible.

If we want those data for reporting we need to do some code change in the website page as well as we need to create some fields in the Live Agent Transcript Object.

Here is the code,

<html>

<script type='text/javascript' src='https://c.la3-c1cs-was.salesforceliveagent.com/content/g/js/36.0/deployment.js'></script>
<script type='text/javascript'>
liveagent.init('https://d.la3-c1cs-was.salesforceliveagent.com/chat', 'XXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX');
liveagent.addCustomDetail("9.First Name", "Priya").saveToTranscript("First_Name__c");
liveagent.addCustomDetail("8.Last Name", "Mohanraj").saveToTranscript("Last_Name__c");
liveagent.addCustomDetail("7.Email", "priyamohanraj754@gmail.com").saveToTranscript("Email__c");
liveagent.addCustomDetail("4.Display Name", "Priya").saveToTranscript("Display_Name__c");
liveagent.addCustomDetail("3.User Name", "priya").saveToTranscript("User_Name__c");
liveagent.addCustomDetail('5.Language', 'English').saveToTranscript("Language__c");
liveagent.addCustomDetail('6.Country', 'India').saveToTranscript("Country__c");
liveagent.addCustomDetail('1.User ID', '1234').saveToTranscript("User_ID__c");
liveagent.addCustomDetail('2.Full Name', 'Priya Mohanraj').saveToTranscript("Full_Name__c");

</script>
<img id="liveagent_button_online_XXXXXXXXXXXXXXXX" style="display: none; border: 0px none; cursor: pointer" onclick="liveagent.startChat('XXXXXXXXXXXXXXX')" src="https://english.na2.force.com/liveagentbutton/resource/XXXXXXXXXXXXXXX/livechatbtnonline" />
<img id="liveagent_button_offline_XXXXXXXXXXXXXXX" style="display: none; border: 0px none; " src="https://english.na2.force.com/liveagentbutton/resource/XXXXXXXXXXXXXXXX/livechatbtnoffline" />
<script type="text/javascript">
if (!window._laq) { window._laq = []; }
window._laq.push(function(){liveagent.showWhenOnline('XXXXXXXXXXXXX', document.getElementById('liveagent_button_online_XXXXXXXXXXXXXXX'));
liveagent.showWhenOffline('XXXXXXXXXXXXXXXX', document.getElementById('liveagent_button_offline_XXXXXXXXXXXXXXX'));
});</script>

</html>

In the above code saveToTranscript is doing the magic. If we give this method along with the custom detail then, it will save the data in the Transcript object in the mentioned field. The fields which are mentioned inside of the SaveToTranscript method is a custom fields which we needs to be created in the LiveAgent Transcirpt object in salesforce.

Thanks

Happy Coding!!!

Friday, 29 July 2016

On Click on apex:outputText Tag.


Lets see how to use onclick on the <apex:outputText> Tag.

Its very simple, but it took 3 hours to find the solution for it.

Here you go,

Its just a simple code on Account Object.

VF Page

<apex:page standardController="Account" extensions="outputfielddblclick_extn" id="pg1">
<apex:form id="frm1" >
<apex:pageBlock id="pb1">
<apex:pageBlockSection id="pbs1" >
<apex:outputpanel id="counter">
<table>
 <tr>
<td> <apex:outputText value="Account Name"></apex:outputText> </td>
<td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td>                 
<td> <apex:outputText value="{!Account.Name}"/>
<apex:actionSupport event="ondblclick" action="{!justdisplay}" rerender="counter" status="s1"/>        <!-- Status is not a mandatory -->
</td>
</tr>
</table>
</apex:outputpanel> 
<apex:actionStatus id="s1"> <!-- This status is used in the actionSupport. Its not mandatory -->
<apex:facet name="start">
loading....
</apex:facet>
</apex:actionStatus>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Below is the apex class,

public class outputfielddblclick_extn {

    public outputfielddblclick_extn(ApexPages.StandardController controller) {

    }
    public void justdisplay()
    {
        system.debug('RRRRRRRRInside FunctionRRRRRRRR');
        // your logic here
    }
}

If you double click on the Account Name, it will call the "justdisplay()" method in the class.

Below is the output screen.


It will work on apex:outputfield also.

Happy Coding!!!