{Issue Resolution} Auto-UNfollow a record enabled for Activity feeds in Dynamics CRM 2013/2015

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(“ownerid”,ConditionOperator.Equal,userid));

                    query2.Criteria.AddCondition(new ConditionExpression(“regardingobjectid”, ConditionOperator.Equal, pitch));

                    EntityCollection postFollowCollection = service.RetrieveMultiple(query2);

                    foreach (Entity postFollow in postFollowCollection.Entities)

                    {

                        service.Delete(postFollow.LogicalName,postFollow.Id);

                    }

Hope it helps!

Advertisement

One thought on “{Issue Resolution} Auto-UNfollow a record enabled for Activity feeds in Dynamics CRM 2013/2015

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s