+ Start a Discussion
RiflemanRifleman 

Adding Chatter Followers to Record

Is there a way to add a button or something to a visualforce page that will allow a user to select other users to follow that record in chatter?  For example, I'm working a case and I want Bob to follow the case, so I'd click a button and a user lookup would popup, letting me select Bob and then add him as a follower to that record.

 

Thanks,

Andrew84Andrew84

Appears you can do this with the Chatter API. Here

 

I believe I did something similar to this once with Apex though. Once I find which object I need to work with again I should be able to come up with something.

RiflemanRifleman

Thanks.  I had found the Entity Subscription object, but was lost as to where to go from there.  We're trying to make it so that support managers can choose various CSRs to follow cases.

Andrew84Andrew84

That's exactly the object I was looking for.

 

It requires a ParentId and a SubscriberId to make a record, so I think what you will want to create is a VisualForce page embeded on the Case record with a Lookup field on Users.

http://boards.developerforce.com/t5/Visualforce-Development/How-to-create-Lookup-field-in-Visualforce/m-p/92311#M5752

 

Then you will want a submit button that will run apex to create the record to make the chosen user follow the record.

 

I believe something like this would work:

public class newSubscription(Id CaseId, Id UserId) {

EntitySubscription es = new EntitySubscription(ParentId = CaseId, SubscriberId = UserId);

insert es;

}

 

^^ Untested

As long as you pass in the CaseId (which you could get from the URL) and the UserId (from the Lookup field) you will be able to make that user follow the Case.

 

This example probably wont work exactly for what you need, but I hope it helps point you in the right direction.