0

Can I use apex trigger and the Chatter API to auto - subscribe sales team members to opportunity.

Also, Please explain a scenario if you have worked on any.

1

Just insert a EntitySubscription record for each sales rep.

[EntitySubscription] represents a subscription for a user following a record or another user. A user can subscribe to a record or to another user. Changes to the record and updates from the users are displayed in the Chatter feed on the user's home page, which is a useful way to stay up-to-date with other users and with changes made to records in Salesforce. Feeds are available in API version 18.0 and later.

Therefore you should create a new after insert trigger. The trigger has to populate the field parentID with the opportunity Id and the subscriber Id with the user Id.

1

You can also use the Chatter API (classes in the ConnectApi namespace) in the trigger:

ChatterUsers.ConnectApi.Subscription subscriptionToRecord = ConnectApi.ChatterUsers.follow(Network.getNetworkId(), 'me', '006D000000CtwLa');

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_ConnectAPI_ChatterUsers_static_methods.htm#apex_ConnectAPI_ChatterUsers_follow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.