Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
165 views4 pages

Chatter SOAP API Cheatsheet

The document summarizes the key objects in the Salesforce Chatter data model that support the Chatter collaboration platform. It describes feed items, which aggregate various feeds like group feeds and record feeds. Record feeds track changes to fields for objects that have feed tracking enabled. The document provides examples of queries to retrieve feed items for a given record and retrieve tracked field changes. It also describes entity subscriptions that represent who is following a given user or record.

Uploaded by

Bushera Hilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views4 pages

Chatter SOAP API Cheatsheet

The document summarizes the key objects in the Salesforce Chatter data model that support the Chatter collaboration platform. It describes feed items, which aggregate various feeds like group feeds and record feeds. Record feeds track changes to fields for objects that have feed tracking enabled. The document provides examples of queries to retrieve feed items for a given record and retrieve tracked field changes. It also describes entity subscriptions that represent who is following a given user or record.

Uploaded by

Bushera Hilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Integration Chatter SOAP API Cheat Sheet

Overview Feed Items


This cheat sheet describes the data model that supports the Salesforce Chatter Feed Items is a collection of objects that store certain feed data. These primary objects
collaboration platform. Chatter provides profiles, posts, comments, feeds, and groups. provide a route to most Chatter data. Feed items aggregate various feeds. For example,
CollaborationGroupFeed aggregates posts for groups a user is a member of and record
Each of these items can be found in the data model, exposed on Force.com. Using this
feeds aggregate posts made on that record and changes to tracked record fields. There is a
data model, you can extend your own applications with Chatter support, or build new
record feed for each object that is enabled for feed tracking.
ones with the Chatter platform.
The Type field of the object indicates whether the feed item represents a UserStatus,
TextPost, LinkPost, ContentPost, DashboardComponentSnapshot, ApprovalPost,
CollaborationGroupCreated, or TrackedChange. If the type is TrackedChange, the
FeedTrackedChange object stores additional data. Any other type means that the feed
stores the additional data, such as AccountFeed or CollaborationGroupFeed.

Each feed item represents either a set of changes on a specific record or a post to a
particular user or record, as indicated by the ParentId field. For instance, when you post to
a feed, the ParentId of the resulting feed item, holds your UserId. Note that some queries
and statements, for example adding a comment, require the ID of a feed item.

Fields include:
• Type: The type of feed item. Values are UserStatus, TextPost, LinkPost, ContentPost,
DashboardComponentSnapshot, ApprovalPost, or TrackedChange.
• CreatedDate: The date and time when the feed item was created.
• CreatedById: The ID of the user who created the feed item.
• InsertedById: If the CreatedById specifies a different user than the user who is
currently logged in (only possible via API inserts), the InsertById is the ID of the user
Chatter Data Model who created the record. This is useful for integrations and data imports.

The data model diagram shows the most important objects found in the Chatter data model. • ParentId: The ID of the user, record, or group that is tracked in the feed.

When feed tracking is enabled for an object, the object’s record feed aggregrates changes
too the tracked fields by feed items. Record feeds for standard objects are named after the
object. For example, an AccountFeed object represents the record feed for Account. For
custom objects like Foo__c the record feed name is Foo__Feed. The FeedTrackedChange
object stores the field change details.
Topic ContentDocument
OpportunityFeed Query
ID OpportunityId = <Id of an opportunity>;
List<OpportunityFeed> oRFeed = [
TopicAssignment FeedComment SELECT Id, Type, CreatedBy.Name, Parent.Name, Body
FROM OpportunityFeed WHERE ParentId = :OpportunityId
ORDER BY CreatedDate DESC, Id DESC LIMIT 20
FeedTrackedChange FeedLike ];

This query displays the 20 most recent opportunity feed items.

Record Detail Page Query


ID accountId = <Id of an Account>;
List<AccountFeed> aRFeed = [
SELECT Id, Type, CreatedDate, CreatedById, CreatedBy.Name,
ParentId, Parent.Name, FeedItemId, Body,
Title, LinkUrl,
(SELECT Id, FieldName, OldValue, NewValue
FROM FeedTrackedChanges),
(SELECT Id, CreatedDate, CreatedById,
CreatedBy.Name, CommentBody
FROM FeedComments ORDER BY CreatedDate DESC)
FROM AccountFeed WHERE ParentId = :accountId
ORDER BY CreatedDate DESC, Id DESC LIMIT 10
];

This query displays the items on the detail page for an account record. You can modify
the query to work with other record feeds by replacing AccountFeed with a different
record feed.

http://developer.salesforce.com
FeedTrackedChange EntitySubscription
The FeedTrackedChange object stores individual field changes on records that belong to The EntitySubscription object represents subscriptions. Subscriptions specify which users
objects that have feed tracking enabled. Query this object only through a record feed. or records a user is following, or who is following a user or record.
Fields: ParentId (ID of the user or record being followed), SubscriberId (ID of the user
Fields: Id, FieldName (name of the field that was changed), OldValue, NewValue, following the record)
FeedItemId (ID of the feed item that represents the record feed item with the changed field)
Query for Followers of a User or Record
Query for Tracked Changes to a Record ID uid = <Id of User or Record>;
ID OpportunityId = <Id of an opportunity>; List<EntitySubscription> followers = [
List<OpportunityFeed> oEFeedT = [ SELECT Id, SubscriberId, Subscriber.Name
SELECT Id, Type, CreatedBy.Name, Parent.Name, FROM EntitySubscription WHERE ParentId = :uid
(SELECT OldValue, NewValue FROM FeedTrackedChanges) ];
FROM OpportunityFeed
Query for Users and Records I Follow
WHERE ParentId = :OpportunityId AND Type = ‘TrackedChange’
ID uid = <Id of User>;
ORDER BY CreatedDate DESC, Id DESC LIMIT 20
EntitySubscription[] followingES = [
];
SELECT Id, ParentId, SubscriberId, Parent.Name
In this example ParentId points to an opportunity record and the query returns all FROM EntitySubscription WHERE SubscriberId = :uid
OpportunityFeed (a record feed) items about that opportunity. ];

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

Query for Subscriptions to Records


CollaborationGroup ID uid = <Id of User>;
List<EntitySubscription> les = [
The CollaborationGroup object represents Chatter groups. SELECT Id, Parent.Name FROM EntitySubscription
WHERE SubscriberId = :uid AND ParentId IN
Fields: Name, Description, OwnerId, CollaborationType (Public or Private), CanHaveGuests (SELECT Id FROM Account WHERE NumberOfEmployees >= 10)
];
The CollaborationGroup object has an associated record feed called
CollaborationGroupFeed, which aggregates the feed items associated with a group. Use This query lists accounts a user follows that have more than ten employees.
CollaborationGroupFeed like any other record feed.

Groups Query
List<CollaborationGroup> oG = [SELECT Name, Description,
CollaborationType, OwnerId from CollaborationGroup]; FeedComment
The query returns a list of all Chatter groups. The CollaborationType field is either Private The FeedComment object stores comments and is a child object of an associated record
or Public. feed item. Each FeedComment is associated with a feed item. Query this object only a
record feed.
Group’s Feed Query
ID cgid = <Id of a group>; Fields: CommentBody (the string representing the comment’s text), FeedItemId (ID of
List<CollaborationGroupFeed> ic = [ the feed item on which the comment was made), ParentId (ID of the record associated
SELECT Id, Type, ParentId, Parent.Name, Body, Title, with the comment), CreatedById (ID of the user who added this item)
(SELECT Id, FieldName, OldValue, NewValue
FROM FeedTrackedChanges ORDER BY Id DESC), CreatedById can be modified to the ID of the original poster during migration. ParentId
(SELECT Id, CommentBody, CreatedDate, CreatedById, either points to a record that received a comment, or to a user whose post received a
CreatedBy.FirstName, CreatedBy.LastName comment. The functionally is equivalent to the associated feed item’s parent.
FROM FeedComments
ORDER BY CreatedDate DESC, Id DESC LIMIT 4) Creating a Comment
FROM CollaborationGroupFeed WHERE ParentId = :cgid FeedComment fcomment = new FeedComment();
ORDER BY CreatedDate DESC, Id DESC LIMIT 20 fcomment.FeedItemId = <feedItemId>;
]; fcomment.CommentBody = ‘This is a profound comment.’;
insert fcomment;

Changes to a group’s name, description or similar fields appear as tracked changes on the You need the ID of a feed item to create comment. All the queries on record feeds return
group’s feed. The query retrieves the tracked change values as well as comments on posts. feed item records.

CollaborationGroupMemberRequest ContentDocumentLink
The ContentDocumentLink object represents the link between a Salesforce CRM Content
The CollaborationGroupMemberRequest object represents a request to join a private document or Chatter file and where it’s shared. A file can be shared with other users,
Chatter group. Chatter groups, records, and Salesforce CRM Content workspaces.
The following query retrieves the Title and Description of the latest version of a document
Fields: CollaborationGroupId (ID of the CollaborationGroup), RequesterId (ID of
loaded via Chatter:
the user requesting to join the group), ResponseMessage (optional message), Status
(status of the request) SELECT ContentDocument.LatestPublishedVersion.Title,
ContentDocument.LatestPublishedVersion.Description
On create(), an email is sent to the owner and managers of the private group. FROM ContentDocumentLink
When they accept or decline the request, the Status changes to Accepted or WHERE LinkedEntityid = ‘<entity-id>’
Declined, and an email is sent to notify the requester. If the request is declined, a
ResponseMessage can be included to provide additional details.
CollaborationGroupMember Creating a Text Post
The CollaborationGroupMember object associates Chatter group members with FeedItem fItem = new FeedItem();
Chatter groups. fItem.Type = ‘TextPost’;
Fields: CollaborationGroupId (ID of the CollaborationGroup), MemberId (ID of the fItem.ParentId = <Id of User or Record>;
user who is a member) fItem.Body = ‘The mice will see you now’;
insert fItem;
Members of a Group Query
ID cg = <Id of a Chatter group>; Note that you can’t create a post of type UserStatus.
List<CollaborationGroupMember> oM = [
See the following queries for additional examples:
SELECT MemberId, CollaborationGroup.Name
FROM CollaborationGroupMember WHERE CollaborationGroupId = :cg • Chatter Tab Query
• Record Detail Page Query
];
• Profile Tab Query
The query returns the IDs of members for a particular Chatter group.

Adding a User to a Group


ID uid = <Id of a user>;
ID cgid = <Id of a group>;
CollaborationGroupMember cgm = new CollaborationGroupMember( Chatter Triggers
memberid = uid, collaborationgroupid = cgid);
insert cgm; You can create Apex triggers on the FeedItem and FeedComment objects.You can’t create
triggers on record feeds, but you can have triggers run based on events in a record feed.
Triggers only support inserts and deletes. Only FeedItems of Type TextPost, LinkPost, and
ContentPost can be inserted.
CollaborationInvitation
Apex code uses additional security when executing in a Chatter context.
Use the CollaborationInvitation object to create or delete (cancel) invitations to join
Chatter. You can invite a user to join Chatter directly or as part of a CollaborationGroup. To post to a private group, the user running the code must be a member of that group.
When users accept your CollaborationGroup invitation, they join the CollaborationGroup If the user isn’t a member, you can set the CreatedById field to be a member of the group
and Chatter as well. in the FeedItem record.

Invited users can view profiles, post on their feed, and join groups, but they can’t see your This example is a trigger that takes an action everytime someone posts a specific key word
data or records. to an entity feed. For example, you may want to perform an action on a record based on a
special keyword (e.g a ‘!close’ post closes an Opportunity).

Trigger CheckChatterPostsOnOpportunity on FeedItem (before insert)


{
// Get the key prefix for the Opportunity object
// using a describe call.
DisableFeedTrackingHeader String oppKeyPrefix = Opportunity.sObjectType.
getDescribe().getKeyPrefix();
The DisableFeedTrackingHeader is a SOAP header that specifies whether the changes for (FeedItem f: trigger.new)
made in the current call are tracked in feeds. When a user subscribes to a record, changes {
to the record display in the Chatter feed on the user’s home page. String parentId = f.parentId;
// Compare the start of the ‘parentID’ field
Use this header if you want to process a large number of records without tracking the // to the Opportunity key prefix to
changes in various feeds related to the records. This header is available if the Chatter // restrict the trigger to act on posts made to the
feature is enabled for your organization. // Opportunity object.
if (parentId.startsWith(oppKeyPrefix) &&
Fields: disableFeedTracking (If true, the changes made in the current call are not tracked f.Body == ‘!close’)
in feeds.) {
// Add your business logic here
}
}
}

Writing Efficient Chatter Triggers


Writing Efficient SOQL Queries • Remember all triggers run in bulk.

• ALWAYS use a LIMITS clause. Feeds generally show 20 items per page. • Use isEmpty to restrict logic execution.

• Refactor common logic out of a trigger.


• Use efficient filters:
-- Most triggers work with FeedItem or FeedComment.
-- ParentId, Id
-- ParentType • Remember that UserStatus is on the User Object.
-- CreateById
• Filter FeedItem execution:
• For record feeds, include ParentID=<recordID> -- On Post types of triggers: TextPost, LinkPost, ContentPost.
• Use the ORDER BY CreateDate DESC, ID DESC format to show most -- On Object types of triggers, use this format:
recent feed items. <object>.sObjectType.getDescribe().getKeyPrefix();

http://developer.force.com
For other cheatsheets: http://developer.force.com/cheatsheets 11182013

You might also like