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

Recently one of the requirement that was asked to one of my fellow community members was to auto-follow an opportunity record, once it is created.

Opportunity entity is automatically enabled for Activity feeds, so I will not get to those bits.Here is the code to achieve the same:


    //ID of the user for which auto-follow needs to be enabled

Guid userid = new Guid(“878D274D-8375-E411-80D0-AC162DB47C44”);

  //ID of the record for which auto-follow needs to be enabled

                    Guid pitch = new Guid(“D3B9BEBB-9076-E411-80D9-AC162DB46F8A”);

                    Entity postfollow = new Entity(“postfollow”);

                    postfollow.Attributes[“regardingobjectid”] = new EntityReference(“opportunity”, pitch);

                    postfollow.Attributes[“ownerid”] = new EntityReference(“systemuser”, userid);

                    Guid postfollowId = service.Create(postfollow);


I think it is a very useful piece of code, as there are not enough code samples on this feature.

Hope it helps!