Developing Apex Triggers for Chatter

16
Developing Apex Triggers for Chatter Chad Smith, Senior Consultant Alternative Technology Solutions @chad_w_smith

description

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.

Transcript of Developing Apex Triggers for Chatter

Page 1: Developing Apex Triggers for Chatter

Developing Apex Triggers for ChatterChad Smith, Senior Consultant

Alternative Technology Solutions@chad_w_smith

Page 2: Developing Apex Triggers for Chatter

Safe harborSafe 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 salesforce.com, 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 non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, 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. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.

Page 3: Developing Apex Triggers for Chatter

Chad SmithSenior Consultant, Alternative Technology Solutions

@chad_w_smith#SFChatterTrigger

Page 4: Developing Apex Triggers for Chatter

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

Page 5: Developing Apex Triggers for Chatter

… before we begin▪ Who is using Chatter now?▪ Who is using trigger with Chatter?▪ Who has written a trigger before?

Page 6: Developing Apex Triggers for Chatter

Trigger Architecture▪ Problems with multiple triggers on the same object

• Cannot control order of execution• Organization of the org

▪ Solution• Single trigger per object• Processing and DML

done within utility classTrigger

Class Code

Class Code

DML Statement

Page 7: Developing Apex Triggers for Chatter

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

Page 8: Developing Apex Triggers for Chatter

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

Page 9: Developing Apex Triggers for Chatter

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_collaborationgroupmember.htm

Page 10: Developing Apex Triggers for Chatter

Object Model

Page 11: Developing Apex Triggers for Chatter

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

Page 12: Developing Apex Triggers for Chatter

Example #2 – Manager Auto-Follow for Big Deals ▪ Set manager of a user to follow any opportunity over $5,000.▪ Code Walk Through

Page 13: Developing Apex Triggers for Chatter

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

Page 15: Developing Apex Triggers for Chatter

Chad SmithSenior Consultant,

Alternative Technology Solutions

@chad_w_smith

Page 16: Developing Apex Triggers for Chatter