0% found this document useful (0 votes)
97 views

Chatter-Cheatsheet Final

This cheat sheet describes the Salesforce Chatter data model, which includes profiles, status updates, posts, comments, feeds, and groups. The key objects are UserProfileFeed, NewsFeed, and RecordFeeds which aggregate posts and comments. FeedItems represent individual posts or tracked changes and can be of different types. FeedPosts store details about individual posts while FeedComments and FeedTrackedChanges store additional data like comments and record changes.

Uploaded by

rajababhu3205
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Chatter-Cheatsheet Final

This cheat sheet describes the Salesforce Chatter data model, which includes profiles, status updates, posts, comments, feeds, and groups. The key objects are UserProfileFeed, NewsFeed, and RecordFeeds which aggregate posts and comments. FeedItems represent individual posts or tracked changes and can be of different types. FeedPosts store details about individual posts while FeedComments and FeedTrackedChanges store additional data like comments and record changes.

Uploaded by

rajababhu3205
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Chatter Cheat Sheet

Overview Chatter Data Model

This cheat sheet describes the data model that supports the Salesforce Chatter collaboration The following diagram depicts the most important objects found in the Chatter data model.
platform. Chatter provides profiles, status updates, posts, comments, feeds, and groups - and
each of these items can be found in the data model, exposed on Force.com. Using this data
model, you can extend your own applications with Chatter support, or build new ones with the User | Object
Chatter platform.

Feed Items

FeedPost UserProfileFeed

FeedComment
NewsFeed
FeedTrackedChange

Record Feeds

User EntitySubscription User | Object


subscriberId parentId

(follower) (followed)

CollaborationGroup CollaborationGroupMember

Three primary objects provide a route to most Chatter data:

- The UserProfileFeed aggregates posts and tracked changes a user has made
- The NewsFeed aggregates posts on users and records that a user is following
-R
 ecord feeds, one for each object that is enabled for feed tracking, aggregate posts
that indicate changes to record data

Collectively, the items in these feeds are called feed items.

Not all data about a post is stored in a feed item. Comments are stored in FeedComment
records, the details about a tracked change are stored in FeedTrackedChange records,
and the data in a post (such as the text of the post itself) is stored in a FeedPost record.
None of these three objects can be queried directly. Instead, query them through a
UserProfileFeed, NewsFeed or record feed.

Feed Items FeedPost


Though not an object, feed items is a term for the records found in a NewsFeed, Stores most information about a post. Depending on type, different fields will be populated.
UserProfileFeed or record feeds. Each feed item is associated with either a set of tracked All FeedPost records contain a FeedItemId field pointing back to the feed item. Query this
changes to a record, or a FeedPost. object only through a UserProfileFeed, NewsFeed or record feed. Fields include:
• FeedItemId - ID of the item containing the FeedPost
The Type field indicates whether the feed item represents a UserStatus, TextPost, LinkPost, • Body - required content of a TextPost or UserStatus, optional for other types
ContentPost or TrackedChange. If it's of type TrackedChange, additional data is in the • LinkURL - URL of a LinkPost
FeedTrackedChange object. If it's of any other type, FeedPost holds the additional data. • Title - title of a link in a LinkPost
• ContentType - The MIME type of the attachment for ContentPosts (read only)
Each feed item represents either a set of changes on a specific record or a post to a • ContentSize - the size of the attachment for ContentPosts (read only)
particular user or record, indicated by its ParentId field. For instance, when you update • ContentFileName - the file name of the attachment for ContentPosts
your status, the ParentId of the resulting feed item, holds your UserId. Note that some • ContentDescription - description of the attachment for ContentPosts
queries and statements, for example adding a comment, require the ID of a feed item. • ContentData - Base64-encoded attachment for ContentPosts
Fields include:
• Type - one of UserStatus, TextPost, LinkPost, ContentPost or TrackedChange While you cannot read FeedPost records directly, you can insert them. ParentId can point
• CreatedDate - when the feed item was created to a user or a record that is tracked.
• CreatedBy - the user who made the change or post
• ParentId - the ID of the user or record about which the feed item was created

http://developer.force.com 6/7/10
Create a new Text Post This lists an abbreviated form of the Chatter feed on your Home tab. CreatedBy.Name
FeedPost fpost = new FeedPost(); indicates who created the item. Parent.Name is your name (if someone posted on your
fpost.Type = 'TextPost'; User record) or a record or user's name (if someone posted on a record or user you
fpost.ParentId = <Id of User or Record>; follow), while FeedPost.Body is non-null if the item isn't of type TrackedChange.
fpost.Body = 'The mice will see you now';
insert fpost;
Home Tab Query
List <NewsFeed> aNewsFeed = [
Other Examples SELECT Id, Type, CreatedDate, CreatedById, CreatedBy.Name,
See the following queries for additional examples: ParentId, Parent.Name, FeedPostId, FeedPost.Body,
• Home Tab Query FeedPost.Title, FeedPost.LinkUrl,
• Record Detail Page Query (SELECT Id, FieldName, OldValue, NewValue
• Profile Tab Query FROM FeedTrackedChanges),
(SELECT Id, CreatedDate, CreatedById,
CreatedBy.Name, CommentBody
FROM FeedComments ORDER BY CreatedDate DESC)
Record Feeds
FROM NewsFeed ORDER BY CreatedDate DESC, Id DESC LIMIT 10
An object with feed tracking enabled, has changes to tracked fields aggregated by feed items
];
in its record feed. Each such object has its own record feed. Record feeds for standard
objects are named after the object, so Account has an AccountFeed object representing its
This query is used to display the items on the Home tab. See Profile Tab Query for a
record feed, while custom objects like Foo__c have a record feed named Foo_Feed__c. The
description of the return values.
actual details of the field change are stored in the FeedTrackedChange object.

Fields: FeedPostId (ID of associated FeedPost), ParentId (ID of record being tracked), Type
UserProfileFeed
This object aggregates feed items that represent all posts and all tracked changes that a
OpportunityFeed Feed Items on a Record
user has made. This feed displays in the Profile tab of the Salesforce Chatter application.
ID OpportunityId = <Id of an opportunity>;
List<OpportunityFeed> oRFeed = [ Think of it as feed items that have a CreatedBy or ParentId mapping to the user.
SELECT Id, Type, CreatedBy.Name, Parent.Name, FeedPost.Body
FROM OpportunityFeed WHERE ParentId = :OpportunityId Fields: FeedPostId (ID of the associated FeedPost), ParentId (ID of the user or record), Type
ORDER BY CreatedDate DESC, Id DESC LIMIT 20
]; Notes:
• When querying this feed, you must include a WITH clause and specify the UserId of
the user whose profile you want to query
Record Detail Page Query
• FeedPostId is null if the instance of UserProfileFeed represents a record update
ID accountId = <Id of an Account>;
List<AccountFeed> aRFeed = [
SELECT Id, Type, CreatedDate, CreatedById, CreatedBy.Name, UserProfileFeed Feed Items indicating Posts a User has Made
ParentId, Parent.Name, FeedPostId, FeedPost.Body, ID userID = <id of User>;
FeedPost.Title, FeedPost.LinkUrl, List <UserProfileFeed> uposts = [
(SELECT Id, FieldName, OldValue, NewValue SELECT Id, FeedPost.Body, Type, Parent.Name
FROM FeedTrackedChanges), FROM UserProfileFeed WHERE Type = 'TextPost'
(SELECT Id, CreatedDate, CreatedById, WITH UserId=:userId
CreatedBy.Name, CommentBody ORDER BY CreatedDate DESC, Id DESC LIMIT 10
FROM FeedComments ORDER BY CreatedDate DESC) ];
FROM AccountFeed WHERE ParentId = :accountId
ORDER BY CreatedDate DESC, Id DESC LIMIT 10 This lists the 10 most recent feed items that are associated with text posts, and the
]; associated post contents. Note the WITH clause, used to specify which user's profile to
query. If you omit the WHERE clause, then all types of feed items are returned, including
This query is used to display the items on an account record's detail page. This query tracked changes. For tracked changes, FeedPost is null. ParentId points to the record
works for any record feed - simply replace AccountFeed with a different record feed. See that was updated.
Profile Tab Query for a description of the return values.
Profile Tab Query
ID userID = <id of User>;
NewsFeed List <UserProfileFeed> = [
This object aggregates feed items that represent a user's posts, as well as posts on SELECT Id, Type, CreatedDate, CreatedById, CreatedBy.Name,
ParentId, Parent.Name, FeedPostId, FeedPost.Body,
users and records that the user is following. This feed displays on the Home tab in the
FeedPost.Title, FeedPost.LinkUrl,
Salesforce Chatter application. Think of it as feed items whose ParentId is the user,
(SELECT Id, FieldName, OldValue, NewValue
or whose ParentId is in the set of users or records the user follows (represented by
FROM FeedTrackedChanges),
EntitySubscription records). You can only query your own NewsFeed. (SELECT Id, CreatedDate, CreatedById,
CreatedBy.Name, CommentBody
Fields: FeedPostId (ID of associated FeedPost), ParentId (ID of the user or record being FROM FeedComments ORDER BY CreatedDate DESC)
tracked), Type FROM UserProfileFeed WITH UserId = :userId
ORDER BY CreatedDate DESC, Id DESC LIMIT 10
Notes: ];
• If a follower, Jack, posted on a record you follow, Acme, then ParentId points to Acme
• Use the CreatedBy system field to determine who made the post This query is used to display the items on the Profile tab. The nested selects return a
set of records for each UserProfileFeed record. If there are comments on the feed item,
FeedComments represents those comments, otherwise it is null. If the feed item is of
NewsFeed Feed Items on Users and Records I Follow type TrackedChange, there are one or more FeedTrackedChange records associated
List <NewsFeed> aNewsFeed = [ with the feed item, representing all of the tracked field changes made during a single
SELECT Id, Type, CreatedBy.Name, Parent.Name, FeedPost.Body update to a record. The user running the query may not have field-level security access
FROM NewsFeed to all the fields that were changed, and so may not have access to the corresponding
ORDER BY CreatedDate DESC, Id DESC LIMIT 20 FeedTrackedChanges records either. As a result, the set of FeedTrackedChanges might
be null for that user.
];
FeedTrackedChange CollaborationGroup
This object stores individual field changes on records that belong to objects that have feed This object represents Chatter groups.
tracking enabled. Query this object only through a UserProfileFeed, NewsFeed or record feed.
Fields: Name, Description, OwnerId, CollaborationType (Public or Private)
Fields: Id, FieldName (name of the field that was changed), OldValue, NewValue, FeedItemId
(ID of the feed item that represents the record feed item on which the field changed) The CollaborationGroup object has an associated record feed called
CollaborationGroupFeed, which aggregates the feed items associated with a group. Use
Tracked Changes to a Record CollaborationGroupFeed as you would any other record feed.
ID OpportunityId = <Id of an opportunity>;
List<OpportunityFeed> oEFeedT = [ List Groups
SELECT Id, Type, CreatedBy.Name, Parent.Name, List<CollaborationGroup> oG = [SELECT Name, Description,
(SELECT OldValue, NewValue FROM FeedTrackedChanges) CollaborationType, OwnerId from CollaborationGroup];
FROM OpportunityFeed
WHERE ParentId = :OpportunityId AND Type = 'TrackedChange' This query returns a list of all Chatter groups. The CollaborationType field will either be
ORDER BY CreatedDate DESC, Id DESC LIMIT 20 Private or Public.
];
List a Group's Feed
Because ParentId points to an opportunity record, this query returns all OpportunityFeed ID cgid = <Id of a group>;
(a record feed) items about that opportunity. List<CollaborationGroupFeed> ic = [
SELECT Id, Type, ParentId, Parent.Name, FeedPost.Id,
FeedPost.Type , FeedPost.Body, FeedPost.Title,
FeedComment (SELECT Id, FieldName, OldValue, NewValue
This object stores comments. A FeedComment is a child object of an associated FROM FeedTrackedChanges ORDER BY Id DESC),
UserProfileFeed, NewsFeed, or record feed item. Each FeedComment is associated with (SELECT Id, CommentBody, CreatedDate, CreatedById,
a feed item. Query this object only through a UserProfileFeed, NewsFeed or record feed.
CreatedBy.FirstName, CreatedBy.LastName
FROM FeedComments
Fields: CommentBody (the string representing the comment's text), FeedItemId (ID of the
ORDER BY CreatedDate DESC, Id DESC LIMIT 4)
feed item on which the comment was made), ParentId (ID of the record associated with
FROM CollaborationGroupFeed WHERE ParentId = :cgid
the comment)
ORDER BY CreatedDate DESC, Id DESC LIMIT 20
Note: ];
• ParentId either points to a record on which a comment was left, or a User on whose
post a comment was left - functionally equivalent to the associated feed item's parent. Changes to a group's name, description or similar fields appear as tracked changes on
the group's feed. This query ensures the tracked change values are retrieved, as well as
Create a Comment comments on posts.
FeedComment fcomment = new FeedComment();
fcomment.FeedItemId = <feedItemId>;
fcomment.CommentBody = 'This is a profound comment.';
CollaborationGroupMember
This object associates Chatter group members with Chatter groups.
insert fcomment;
Fields: CollaborationGroupId (Id of the CollaborationGroup), MemberId (ID of the user
You need the ID of a feed item for this to work. All the queries on the UserProfileFeed,
who is a member)
NewsFeed and record feeds return feed item records.
List Members of a Group
Other Examples
ID cg = <Id of a Chatter group>;
See the following queries for additional examples:
List<CollaborationGroupMember> oM = [
• Home Tab Query
• Record Detail Page Query SELECT MemberId, CollaborationGroup.Name
• Profile Tab Query FROM CollaborationGroupMember WHERE CollaborationGroupId = :cg
];

EntitySubscription This query returns the IDs of members for a particular Chatter group.
This object represents a subscription of a user. Use it to determine which users or
records a user is following, or who is following a user or record. Add a User to a Group
ID uid = <Id of a user>;
Fields: ParentId (ID of the user or record being followed), SubscriberId (ID of the user ID cgid = <Id of a group>;
following the record) CollaborationGroupMember cgm = new CollaborationGroupMember(
memberid = uid, collaborationgroupid = cgid);
Followers of a User or Record insert cgm;
ID uid = <Id of User or Record>;
List<EntitySubscription> followers = [
SELECT Id, SubscriberId, Subscriber.Name CurrentStatus
FROM EntitySubscription WHERE ParentId = :uid
Update a user’s status by updating the CurrentStatus field of the User record. Updating
];
the field will also ensure that UserProfileFeed is updated.
List the Users and Records I Follow
ID uid = <Id of User>; Update a User's Status
EntitySubscription[] followingES = [ ID uid = <Id of User>;
SELECT Id, ParentId, SubscriberId, Parent.Name User user = [SELECT Id, CurrentStatus FROM User WHERE Id = :uid];
FROM EntitySubscription WHERE SubscriberId = :uid user.CurrentStatus = 'new and exciting status message';
]; update u;

To only show users, add Parent.Type='User' to the WHERE clause.


This retrieves a User record, sets the CurrentStatus field, and updates the record.
List Subscriptions to Records
ID uid = <Id of User>;
List<EntitySubscription> les = [
SELECT Id, Parent.Name FROM EntitySubscription
WHERE SubscriberId = :uid AND ParentId IN
(SELECT Id FROM Account WHERE NumberOfEmployees >= 10)
];

This lists accounts a user follows that have more than 10 employees.
2010

You might also like