In one of my earlier blogs I had shown how to automatically follow a record using code. Some of the community members wanted to unfollow also using code.
Opportunity entity is automatically enabled for Activity feeds, so I will not get to those bits.Here is the code to achieve the same
Link for the auto follow a record using code is : dynamicsofdynamicscrm.wordpress.com/…/issue-resolution-auto-follow-a-record-enabled-for-activity-feeds-in-dynamics-crm-20132015
There is no official code samples available, hence this piece of code also becomes very important:
//ID of the user
Guid userid = new Guid(“CE4C5141-9941-456B-9007-FBC3C5F02E8E”);
//ID of the record for which auto-follow needs to be disabled
Guid pitch = new Guid(“3B5DE3B0-79A2-E411-80DE-C4346BAD5280”);
QueryExpression query2 = new QueryExpression(“postfollow”);
query2.Criteria.AddCondition(new ConditionExpression(“regardingobjectid”, ConditionOperator.Equal, pitch));
EntityCollection postFollowCollection = service.RetrieveMultiple(query2);
foreach (Entity postFollow in postFollowCollection.Entities)
Hope it helps!