Home SALESFORCEAPEX How to follow entities (Accounts, Contact, Opportunities, Custom Objects) in Chatter?

How to follow entities (Accounts, Contact, Opportunities, Custom Objects) in Chatter?

SFDC-Interview-Questions-AnswersBy Adding records to the ‘EntitySubscription‘ object. This object is available only through the API.

EntitySubscription Objects stores which user follows which Account, Contact, or any custom object Record or UserThe fields in this table are
ParentId: The ID of the Account, Contact or any record or User.
SubscriberId: The ID of the user who follows the record denoted in the Parent ID.

To Add followers automatically using Apex Class/Trigger, you could insert records into this object. And to Un-follow just delete the relevant records.

[JAVA]
EntitySubscription newEntity = new EntitySubscription();
newEntity.ParentId = ‘insert relevant SFDC ID’;   //Account, Contact, Custom Object…
newEntity.SubscriberId = ‘insert User ID’; //USER ID
insert newEntity;
[/JAVA]
To Retrive the Follower Information:
For Example:
[JAVA]
List myAccoutFollower = [Select Id, ParentId, SubscriberId from EntitySubscription where ParentId = ‘001Q11100046Vt3’];
[/JAVA]

You may also like

Leave a Comment