Wednesday, 1 February 2012

Follow/UnFollow Records from your Visualforce Page

On observing standard salesforce pages like "All Contacts" view, we note a column called "Action" containing three actions namely,
1. Editing a record
2. Deleteing a record
3. Following or Unfollowing a record as shown below




I have demonstrated 1 and 2 in my previous posts.


Following/Unfollowing a record can be made possible using the tag <chatter:follow> 



The code snippet will be something like,




<apex:pageBlockTable value="{!Contacts}" var="con">
          <chatter:follow entityId="{!con.Id}"/>
.
.
.
</apex:pageBlockTable >

Embedding Chatter in Visualforce Pages


As we know that, Chatter in salesforce makes our applications more collaborative. Chatter can be enabled for both standard and custom objects, making us to know about the changes like new contact created, stage field changes etc., in real-time.

Navigate to the following path to enable Chatter,
Your Name ➤ Setup ➤ Customize ➤ Chatter ➤ Settings

If Chatter is enabled for an organization, it will appear in Users profile page and in Objects Home Page. Embedding Chatter in Visualforce Pages can be made possible by using the <chatter:feed> tag, introduced as a part of Winter '11 Release.



This tag takes the required attribute entityId, which may take values like user Id, record Id from URL etc., as shown below

<apex:page standardController="Opportunity" recordSetVar="Oppties">
<apex:sectionHeader title="List" subtitle="Opportunity"/>
<chatter:feedWithFollowers entityId="{!$User.Id}"/>
<apex:pageMessages />
    <apex:pageBlock >
        <apex:pageBlockTable value="{!Oppties}" var="oppty">
            <apex:column headerValue="Name" value="{!oppty.Name}"/>
            <apex:column headerValue="Stage" value="{!oppty.StageName}"/>
            <apex:column headerValue="Close Date" value="{!oppty.closedate}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

The tag <chatter:feed/> displays Chatter without their followers.

Note: Chatter components are unavailable for Visualforce pages on Force.com sites