Thursday, August 22, 2013

Display Chatter in Visualforce pages

               Display Chatter Widget in VisualForce Pages

Chatter is a very useful widget available to collaborate with other users or a group of users in your Salesforce Org. It is visible (at the bottom corner of the window on right hand side) in all standard Salesforce views. But it will not be visible on custom developed VisualForce pages by default. 

To enable it on VisualForce Pages you need to follow 2 steps.

1) change the default settings. 
    Go to Your Name-->Setup-->Customize-->Chatter-->Chat Settings
       You can see there two options
          1. Chat Settings.
          2. Visualforce Settings.
       Click on Edit & Check the box next to "Allow" under VisualForce Settings.  Click on Save.

2) Set Correct attributes to Visualforce Page <apex:page> tag. 

       You need to add "Showheader=ture" attrubute on the <apex:page> tag.
       If you don't want to show header but chatter widget must be shown, then you have to use two attributes.
           showheader=false
           showchat=true


Example 1:

  <apex:page standardController="Account" showHeader="true">
    <apex:form>
        <apex:pageBlock title="My Content" mode="edit">
            <apex:pageBlockButtons>
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:inputField value="{!account.name}"/>
                <apex:inputField value="{!account.site}"/>
                <apex:inputField value="{!account.type}"/>
                <apex:inputField value="{!account.accountNumber}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Output of this page with chatter widget displaying @ the bottom right hand side corner of the window



Example 2:

<apex:page standardController="Account" showHeader="false" showChat="true">
    <apex:form>
        <apex:pageBlock title="My Content" mode="edit">
            <apex:pageBlockButtons>
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:inputField value="{!account.name}"/>
                <apex:inputField value="{!account.site}"/>
                <apex:inputField value="{!account.type}"/>
                <apex:inputField value="{!account.accountNumber}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Output of this page with chatter widget displaying @ the bottom right hand side corner of the window



To prevent the chat widget from displaying on a specific Visualforce page, do any of the following:
  • Turn off the Salesforce tab header on your page by setting <apex:page showHeader=”false”>.
  • Set the page contentType to something other than text/html, for example, <apex:page contentType="text/plain">.