Newer Version Available
Creating Packaged Applications with Chatter
The objects, field settings, and field settings history of Chatter are packageable. However, an object's field is only tracked if the object itself is tracked. For example, you can create a new custom field on the Account standard object, but the field will only be tracked if you have enabled feed tracking on Accounts.
When developing applications that use Chatter, it's important to be aware
that some organizations might not have Chatter enabled. By default, when you upload Chatter
applications, the package is only available to organizations that have Chatter enabled. You
can change this behavior and allow organizations to install the package even if they don't
have Chatter. Note the following:
- You must use a managed package. Unmanaged packages that include Chatter functionality can only be installed in organizations that have Chatter enabled.
- DML operations and SOSL, and SOQL calls will throw a runtime exception if the subscriber organization does not have Chatter enabled. You must catch and handle any Apex exceptions that are thrown as a result of the missing Chatter feature. These exceptions are of the type REQUIRED_FEATURE_MISSING_EXCEPTION for SOSL and SOQL calls. For DML calls, you must check for the specific REQUIRED_FEATURE_MISSING status code on a DML Exception.
- When you upload the package, deselect the Chatter required checkbox (this is automatically selected if you have an Apex reference to Chatter).
The following example tries to post to feeds and get a user's feed. If
Chatter is not enabled in the organization, the code catches the REQUIRED_FEATURE_MISSING exception. Note that this is an
incomplete code example and does not run.
1public void addFeedItem(String post, Id objId) {
2 FeedItem fpost = new FeedItem();
3 // Get the parent ID of the feed
4 fpost.ParentId = objId;
5 fpost.Body = post;
6 try{
7 insert fpost;
8 } catch (System.DmlException e) {
9 for (Integer i = 0; i < e.getNumDml(); i++) {
10 // Chatter not endabled, do not insert record
11 System.assertEquals(StatusCode.REQUIRED_FEATURE_MISSING, e.getDmlType(i));
12 System.Debug('Chatter not enabled in this organization:' + e.getDMLMessage());
13 }
14 }
15}
16
17 public List<NewsFeed> getMyFeed() {
18 List<NewsFeed> myfeed;
19 try{
20 myfeed = [SELECT Id, Type, CreatedById, CreatedBy.FirstName,CreatedBy.LastName,
21 CreatedDate, ParentId, Parent.Name,FeedItemId, Body,
22 Title, CreatedById, LinkUrl,
23 (SELECT Id, FieldName, OldValue, NewValue
24 FROM FeedTrackedChanges ORDER BY Id DESC),
25 (SELECT Id, CommentBody, CreatedDate, CreatedById,
26 CreatedBy.FirstName, CreatedBy.LastName
27 FROM FeedComments ORDER BY CreatedDate DESC, ID DESC LIMIT 10)
28 FROM NewsFeed
29 ORDER BY CreatedDate DESC, ID DESC LIMIT 20];
30 } catch(System.RequiredFeatureMissingException e){
31 // The above has returned an empty NewsFeed
32 // Chatter is not enabled in this organization
33 myfeed = new List<NewsFeed>{};
34 System.Debug('Chatter not enabled in organization:' + e.getMessage());
35 }
36 return myfeed;
37 }