Developing Apex Triggers for Chatter


Published on

Join us as we explore how to use simple Apex Triggers to make Chatter ever more useful. Specifically, you'll learn how to create Triggers to automatically post Opportunity Next Actions to a Chatter Group, automatically add new users to Chatter groups, and automatically follow and unfollow Salesforce items based on some criteria.

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Developing Apex Triggers for Chatter

  1. 1. Developing Apex Triggers for Chatter Chad Smith, Senior Consultant Alternative Technology Solutions @chad_w_smith
  2. 2. Safe harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available., inc. assumes no obligation and does not intend to update these forward-looking statements.
  3. 3. Chad Smith Senior Consultant, Alternative Technology Solutions @chad_w_smith #SFChatterTrigger
  4. 4. Agenda ▪ Trigger Architecture • Single trigger per object • Utility Class for processing and DML operation ▪ Chatter Objects • FeedItem • EntitySubscription ▪ Example #1 – Auto-post to “Customer Win” Chatter Group ▪ Example #2 – Manager auto-follow “Big Deals” ▪ Example #3 – Auto-add new users to “Salesforce Q&A” Chatter Group
  5. 5. … before we begin ▪ Who is using Chatter now? ▪ Who is using trigger with Chatter? ▪ Who has written a trigger before?
  6. 6. Trigger Architecture ▪ Problems with multiple triggers on the same object • Cannot control order of execution • Organization of the org ▪ Solution Class Code • Single trigger per object • Processing and DML done within utility class Trigger Class Code DML Statement
  7. 7. FeedItem Object ▪ “FeedItem represents an entry in the feed, such as changes in a record feed, including text posts, link posts, and content posts.” ▪ Important Fields • Body (Textarea) – The text or ‘body’ of the post • ParentID (ID) – Chatter Group ID, AccountID, UserID (Profile Post) • Type (Picklist) – TextPost, LinkPost, PollPost ▪ http://www.salesforce. com/us/developer/docs/api/Content/sforce_api_objects_feeditem.htm
  8. 8. EntitySubscription Object ▪ “Represents a subscription for a user following a record or another user.” ▪ Important Fields • NetworkID (ID) – Community ID • ParentID (ID) – ID of the record being followed • SubscriberID (ID) – ID of the user following the record. ▪ Add Link to Docs
  9. 9. CollaborationGroupMember Object ▪ “Represents a member of a Chatter group.” ▪ Important Fields • CollaborationGroupID (ID) – Chatter Group ID • CollaborationRole (Picklist) – Admin or Standard • MemberID (ID) – UserID of the Member • NotificationFrequency (Picklist) – D for Daily, W for Weekly, N for Never, P for Post ▪ http://www.salesforce. com/us/developer/docs/api/Content/sforce_api_objects_collaborationgr oupmember.htm
  10. 10. Object Model
  11. 11. Example #1 – Auto-Post to “Customer Win” Chatter Group ▪ Post information to your “Customer Win” Chatter Group when your opportunity goes to “Closed Won” ▪ Celebrate Victories! ▪ Minimize Emails in favor of Chatter (Chatter Adoption) ▪ Other Ideas • Opportunity Next Action Group • Project Next Action Group ▪ Code Walk Through
  12. 12. Example #2 – Manager Auto-Follow for Big Deals ▪ Set manager of a user to follow any opportunity over $5,000. ▪ Code Walk Through
  13. 13. Example #3 – Add new users to the “Salesforce Q&A” Chatter Group ▪ Salesforce Chatter Group for Salesforce Questions & Answers ▪ Minimize support emails for your Administrator ▪ Drive Salesforce & Chatter Adoption
  14. 14. Deck & Code ▪ Dreamforce Session Chatter ▪ Alternative Technology Solutions Website • Email me! •
  15. 15. Chad Smith Senior Consultant, Alternative Technology Solutions @chad_w_smith