Beruflich Dokumente
Kultur Dokumente
Login
PRODUCTS
RESOURCES
COMMUNITY
BLOG
TRAILHEAD
Home Technical Library
Getting Started
The best way to learn Chatter and get a quick hands-on introduction is
through the [Chatter Basics] module in Trailhead. You can also follow this
brief Getting Started.
Chatter provides collaboration features and capabilities to any application
built on the Force.com platform. These collaboration features include real-
time feed updates, user profiles, and feeds that allow users to see
changes that are important to them. For a developer, this social platform
opens up endless possibilities for customization.
Let's begin at the beginning with User Profiles. A Chatter User Profile
allows a user to share important information about themselves, and allows
other users to learn more about you, including your interests, your
specialties, and more. To update your User Profile, click on the Profile tab
within the Salesforce Chatter Application.
Setting up a User Profile
With our User Profile updated, the next important piece of Chatter we
need to become familiar with is Feed Tracking. Feed Tracking provides
real-time notification of changes to a particular object. System
Administrators may customize Feed Tracking on an object and field basis
via Setup | Customize | Chatter | Feed Tracking. In addition to standard
objects, any custom objects you create automatically appear as 'trackable'
objects.
Feed Tracking on a Custom Object
Once Feed Tracking is enabled for a particular object, users can choose to
follow individual records. For example, let's say I am interested in a new
Opportunity titled New Gravel Pit. By clicking on the follow icon, I have
just subscribed to the Feed and will be notified of any changes to this
record (on tracked fields), and posts added by other users. You can also
choose to follow individuals users and groups, and receive status updates.
Following an Opportunity
All changes to a followed record will automatically add a new status
message to the record's feed. Feed Posts are not limited to textual
comments however, they may also include links and files. In addition,
Users may update their own status messages to let colleagues know what
they are working on.
Sharing your User Status
UserStatus
A UserStatus identifies the post as a status update. The FeedItem created
shall be accessible via the UserProfileFeed. A user's Chatter status is
stored in the 'CurrentStatus' field on the User object. If the textbox for
your post contains the message "What are you working on?", then you are
creating a post of type UserStatus.
LinkPost
A record of type LinkPost shall be created whenever the User clicks the
'Link' field within the UI. Like all other posts, LinkPost types are added to
the FeedItem object, but must be retrieved via an aggregator object like
NewsFeed (see the SOQL statement in the Samples section below).
ContentPost
A record of type ContentPost shall be created whenever the User clicks the
'File' field within the UI, and uploads an attachment. The content data,
filename, description, file size, and type are stored as a FeedItem record.
ContentPost type posts must be retrieved via an aggregator object like
NewsFeed (see the SOQL statement in the Samples section below).
TrackedChange
The TrackedChange type is used whenever a field on a record, previously
identified during Chatter Feed Tracking configuration, is updated. In
addition to the FeedItem being created, a FeedTrackedChange record is
also created, including both the old and new value of the field. You cannot
directly insert a FeedItem of type TrackedChange. This type of Chatter
post is created automatically by the system based on the Chatter Feed
Tracking configuration. We will discuss FeedTrackedChanges in more detail
below.
The following image depicts elements in the UI and which Feed Types are
used as a result:
Entity Feeds
Entity Feeds represent standard or custom objects. For each of the
standard objects, and any custom objects configured for Feed Tracking, an
Entity Feed will be created automatically for you to maintain posts related
to that object . The Chatter Data Model uses the naming convention listed
below for these Entity Feeds:
1. Standard Objects such as Accounts, Contacts, Opportunities:
ObjectNameFeed. For example, OpportunityFeed.
2. Custom Objects: ObjectName__Feed. For example
MyCustomObject__Feed.
Every time a post is made on a tracked object, say Account, a record is
added to the respective Entity Feed with the parentId field representing
the Id of that particular object. In our example, this would be an Account
Id. Querying the AccountFeed would return details about all Chatter posts
made to Account records (unless the change on the object is due to
tracked change, but we will discuss this further below).
The following example returns the 20 most recent Chatter posts for a
given Account, ordered by CreatedDate, and Id descending:
1 SELECT Body, Type, Title, CreatedBy.Name
2 FROM AccountFeed WHERE ParentId = <Account Record Id>
3 ORDER BY CreatedDate DESC, Id DESC LIMIT 20
NewsFeed
The NewsFeed forms a sort of aggregate of posts of all users, groups and
objects a particular user is following. Querying the NewsFeed object for a
particular user would therefore return the same list of Chatter updates
that the user sees on the Home tab of the Salesforce application. A user
can only query their own News Feed. The following query for example
returns the last 20 items from your NewsFeed
1 SELECT Id, Type, Body, Title, CreatedBy.Name
2 FROM NewsFeed
3 ORDER BY CreatedDate DESC, Id DESC LIMIT 20
Querying NewsFeed directly, while possible, is not always the most
effective way to retrieve a particular user's feed (unless, of course you
want everything a User has been posting about, and everything they are
following.). Typically, querying based on Feed Items such as
UserProfileFeed, or a particular Entity Feed is sufficient.
Note also that a NewsFeed includes mentions from other users. A mention
is the @ symbol followed by a persons name, for example, @Bob Smith.
You can mention people in Chatter posts and comments and that
automatically causes the post/comment to appear in that person's Chatter
News Feed.
UserProfileFeed
UserProfileFeed is similar to NewsFeed in the sense that it acts as a
aggregator of information, but unlike NewsFeed, it is specific to a
particular user. UserProfileFeed can be very useful for retrieving a
snapshot of a user's activity. The information obtained from a query to this
view, returns the same information you would receive when clicking on a
person from the People tab within Chatter.
When querying the UserProfileFeed you must use the SOQL function WITH
(introduced in Spring '10), and pass in the id
1 SELECT Id, Type, Body, Title, CreatedBy.Name
2 FROM UserProfileFeed WITH UserId = <User Id>
3 ORDER BY CreatedDate DESC, Id DESC LIMIT 10
Similar to NewsFeed, a UserProfileFeed includes any mentions for the
respective user.
CollaborationGroupFeed
The CollaborationGroupFeed represents the Chatter feed for a specific
Chatter Group (Public or Private). Querying the CollaborationGroupFeed
object for a specific group would result in the same set of posts that are
displayed on the Group home page in Chatter.
1 SELECT Id, Type, Body, CreatedBy.Name
2 FROM CollaborationGroupFeed where parentId = <Group Id>
3 ORDER BY createdDate DESC, Id DESC LIMIT 20
FeedTrackedChanges
During the Feed Tracking configuration, certain fields can be specified to
send Chatter updates. If one of these fields is updated on a record, an
entry shall be added to FeedTrackedChanges containing both the old and
new value of the field (Note: this entry is in addition to any audit history
tracking already established on an Object) with a Feed type of
TrackedChange.
The FeedTrackedChanges object is not directly accessible and must be
accessed via an Entity Feed:
1 SELECT Id, (SELECT Id, FieldName, OldValue, NewValue
2 FROM FeedTrackedChanges )
3 FROM AccountFeed ORDER BY CreatedDate DESC, Id DESC LIMIT 10
FeedComment
Any time a User adds a comment to another User's post, a record is
created in FeedComment with a reference to FeedItemId. The
FeedComment is not directly accessible and must be accessed via an
Entity Feed:
1 SELECT Id, (SELECT Id, CommentBody, CreatedDate, CreatedById,
2 CreatedBy.FirstName, CreatedBy.LastName
3 FROM FeedComments ORDER BY CreatedDate DESC LIMIT 10)
4 FROM AccountFeed ORDER BY CreatedDate DESC, Id DESC LIMIT 10
FeedLike
Users can 'Like' a Chatter post (but not a comment) by clicking on the
respective link under the post. This action adds a record to the FeedLike
object. FeedLike is not directly accessible and must be accessed via its
parent NewsFeed, UserProfileFeed, or entity feed. For example:
1 SELECT Id, (SELECT CreatedById, CreatedBy.FirstName, CreatedBy.LastName
2 FROM FeedLikes ORDER BY CreatedDate DESC)
3 FROM AccountFeed ORDER BY CreatedDate DESC, Id DESC LIMIT 10
EntitySubscription
EntitySubscription records all the users and records that a user is following
in Chatter. In effect, EntitySubscription is a simple junction object between
the subscriber (subscriberId) and the user/record they're following
(parentId). For example, the following query returns all the users and
records that a particular user is following.
1 SELECT id, parentid, subscriberid, parent.name
2 FROM EntitySubscription WHERE subscriberid = <User Id>
1 SELECT ContentDocument.LatestPublishedVersion.Title,
ContentDocument.LatestPublishedVersion.Description
2 FROM ContentDocumentLink
3 WHERE LinkedEntityid = '<entity-id>'
CollaborationInvitation
You can invite people from your company that don't have Salesforce
licenses to use Chatter. Invited users can view profiles, post on their feed,
and join groups but can't see your Salesforce data or records. You can also
invite coworkers to join a public group even if they don't use Chatter yet.
The CollaborationInvitation object represents such a Chatter invitation
request.
The Id returned from the above query can then be used to set the
'FeedItemId' for inserting a comment for that post.
Retrieve Chatter Data
This SOQL statement, although more complex than the other examples,
may be used as a generic query statement. I have
used OpportunityFeed as an example, but you can query any Entity Feed
object by changing the outer FROM clause.
01 SELECT Id, Type,
02 CreatedById, CreatedBy.FirstName, CreatedBy.LastName,
03 ParentId, Parent.Name,
04 Body, Title,
05 (SELECT Id, FieldName, OldValue, NewValue
06 FROM FeedTrackedChanges ORDER BY Id DESC),
07 (SELECT Id, CommentBody, CreatedDate,
08 CreatedById, CreatedBy.FirstName, CreatedBy.LastName
09 FROM FeedComments ORDER BY CreatedDate LIMIT 10),
10 (SELECT CreatedBy.FirstName, CreatedBy.LastName
11 FROM FeedLikes)
12 FROM OpportunityFeed
13 WHERE ParentId = '<opportunity-id>'
14 ORDER BY CreatedDate DESC, Id DESC
15 LIMIT 20
When querying from an Entity Feed, if you dont supply the WHERE
ParentId = <entity-id>, then youll actually get all feed items for all
opportunities that you have access to. This is not always what you intend;
You usually want to query for a specific entity, thus the ParentId as part of
the WHERE clause.
Also, without the ORDER BY CreatedDate DESC on the outer query, youll
get feed items in random order, and it again wont be what you probably
wanted, which is most recent data first. Chatter actually presents
comments on the page in forward time order, and feed items in reverse
order. You probably didnt even notice; other popular social networking
site use this order too, and it is usually how you want to read the data in
your feed. Of course, if you don't want this order, remove the ORDER BY
and DESC in the outer query.
You might have also noticed the inclusion of the 'Id DESC' clause in this
and other queries referenced in the article. Adding this sort order, while of
no consequence to the query result, significantly improves the
performance of Chatter feed queries. It is therefore a general best practice
to include 'Id DESC' sort order in all feed queries.
Finally, the LIMIT clause is important. In fact, when querying from
NewsFeed (and in certain conditions, some other objects like
UserProfileFeed), it is required. You almost never want all of the feed data,
just the most recent. Feeds, by there nature can go large quite quickly,
and performance of your query will be a function of how much data you
pull back. A best practice is to always use the LIMIT keyword.
Developing Chatter Triggers
You can initiate real-time business actions every time someone posts or
comments in Chatter by developing Apex triggers. The triggers can be
written on the FeedItem and FeedComment objects. For example, the
following trigger checks for a specific keyword in posts made to the
Opportunity entity feed :
01 trigger CheckChatterPostsOnOpportunity on FeedItem (before insert) {
02 //Get the key prefix for the Opportunity object via a describe call.
03 String oppKeyPrefix =Opportunity.sObjectType.getDescribe().getKeyPref
ix();
04
05 for (FeedItem f: trigger.new)
06 {
07 String parentId = f.parentId;
//We compare the start of the 'parentID' field to the
08
Opportunity key prefix to
//restrict the trigger to act on posts made to the Opportunity
09
object.
10 if (parentId.startsWith(oppKeyPrefix) &&
11 f.Body == 'any keyword here')
12 {
13 <Add business logic here>
14 }
15 }
16 }
Note the use of the parentId prefix in the trigger code. Since the trigger is
on FeedItem and not on UserProfileFeed or a specific entity feed (like
AccountFeed, OpportunityFeed etc.) you have to examine the prefix of the
'polymorphic' parentId field to determine the type of the parent object for
the chatter post.
Summary
Chatter provides a powerful tool for enabling collaboration within your
organization. By following specific records, standard or custom objects,
users and groups, business users can quickly keep up to date on
information relevant to them.
At its core, Chatter is a social platform which can be extended to build
collaboration-ready applications on Force.com. With point and click
configuration, users can extend their custom applications and objects to
take advantage of the feeds, posts, comments and user status.
By understanding the Chatter Data Model, developers can further extend
their applications to programatically add posts and comments, or even
expose Chatter actions for integration with external systems.
References
Chatter Resource Page - the home of all things Chatter
Chatter Code Recipes - a series of code recipes covering the primary
use cases a developer may encounter when customizing Chatter
SOQL Relationship Queries - a good introduction to get familiar with
SOQL Relationship Queries used regularly when querying Chatter Data
Visit the Chatter Discussion Board
About the Authors
Quinton Wall is a Developer Evangelist at Salesforce.com, and a published
fantasy author. He is a regular speaker at cloud events, contributor to the
developer blogs, and twittersphere. When he is not working with the
Force.com platform, or writing books, you can find him on the web.
Sandeep Bhanot is a Developer Evangelist at Salesforce.com. When not
working on the Force.com platform, he spends most of his time reading
Quinton's fantasy books.
Special thanks to Jon Mountjoy, Rob Woollen, Umit Yalcinalp, Carter
Thaxton, Caroline Roth, Lauren Pederson, and Mark Leonard for their
contributions to the article.
Technical Library
Documentation
Tools
Integration
App Logic
User Interface
Database
Security
Web Sites
Mobile
App Distribution
Newsletter
Release Information
RSS Feeds
Featured Content
Blog
Discussion Boards
Join over 3.0 million Salesforce developers. Subscribe Now!HIDE
Get started
Force.com
Heroku
Desk.com </developers>
Developer resources
Mobile Services
Force.com Docs
Force.com Downloads
Heroku Docs
Heroku Downloads
Community
Developer Forums
Webinars
Learn more
Salesforce AppExchange
Salesforce Administrators
Copyright 2000-2016 salesforce.com, inc. All rights reserved. Various trademarks held by their
respective owners.
Salesforce.com, inc. The Landmark @ One Market, Suite 300, San Francisco, CA 94105, United States
Privacy Statement Security Statement Terms of Use Feedback About Us Language: English