function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PrasanthsagarPrasanthsagar 

Chatter - Auto Follow

I have an opportunity where a User lookup is created to it.

 

Now whenever an opporunity record is created which contains the User lookup too, the user selected in the record should get the chatter feed whenever some changes are done to the opportunity.

 

 

Is this possible using a trigger??? Or any sort of customization??

 

Pls suggest...

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu
Use Account for example, just create a new account

Id aid = [Select Id from Account Order By CreatedDate Desc limit 1].id;
EntitySubscription es = new EntitySubscription();
es.ParentId = aid;
es.SubscriberId = Userinfo.getUserId();
insert es;

Then current user will follow this new account now.

All Answers

Jia HuJia Hu
1. enable the Feed Tracking on Opportunity
2. select Opportunity fields to monitor, up to 20 fields
3. create a Trigger on Opportunity, when a Opportunity record is created, make the looked up user follow this recorder
4. then when this record is updated, in the lookup user's profile page, you will get a Feed Tracking chatter feed
PrasanthsagarPrasanthsagar

Jia Hu, Thank u very much for the reply.

 

The trigger is fine. But could you please eloborate on 'how to make the user to follow this record!!' 

 

Could you provide the code!!!???

 

 

Jia HuJia Hu
Use Account for example, just create a new account

Id aid = [Select Id from Account Order By CreatedDate Desc limit 1].id;
EntitySubscription es = new EntitySubscription();
es.ParentId = aid;
es.SubscriberId = Userinfo.getUserId();
insert es;

Then current user will follow this new account now.
This was selected as the best answer
PrasanthsagarPrasanthsagar

Thank u once again Jia Hu,

 

I have executed the trigger and it is working splendid while inserting the record.

 

But when i try to update 'EntitySubscription' object, I am getting an error 'DML operation UPDATE not allowed on EntitySubscription' .

 

Update operation cant be done on EntitySubscription? 

 

Also, I think there is a governor limit for the number of records a user can follow is 500. Is it correct???

Jia HuJia Hu
doc is here
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_entitysubscription.htm

use insert on EntitySubscription, but no update

I have tested in Apex, no problem. But you have to test it in trigger, may have some extra limits there.

Yes, people and records you can follow is 500
rpp0910rpp0910

Hi ,

 

  We have a Contract custom object with account as parent . If the contract end date is about 180 days , a chatter feed should be placed on account owner chatter page . Any help please.

 

Thanks in advance..

 

 

GeeChaGeeCha
Hi Jia Hu,
Force users to auto-follow Account, Project & Opportunity records that they own OR are on the team of   - Can you suggest the ways?