Dynamics 365 Web API - Follow And Unfollow CRM Core Records

Requirement

Dynamics 365 platform provides feature to Follow and Unfollow records from CRM record form ribbon button and views ribbon button.

Whenever we follow any record in CRM, the System creates a new record in PostFollow entity and record in PostFollow entity will be deleted when we Unfollow the record.

Today I will walk through the approach to achieve the same using WEB API. So to Follow any record in CRM we have to create record in postfollow entities.

Follow Record

Follow and Unfollow CRM Core records

  1. We can replace entity name with any other entity name which support Follow feature in request body
  2. Use Rest Builder Tool to generate code for WEB API
  3. Execute the code and refresh the form voila!

Follow and Unfollow CRM Core records

UnFollow Record

To Unfollow record in CRM we will have to delete the PostFollow entity record. And to delete the record we will have to first get record ID. We can get post follow entity record using regardingobjectid field.

Get PostFollow Record Guid filtered by regradingObjectID and OwnerId

GET https://CRMORG.api.crm8.dynamics.com/api/data/v9.1/postfollows$select=PostFollowId,RegardingObjectId&$filter=(RegardingObjectId/Id%20eq%20guid%27{AAA19CDD-88DF-E311-B8E5-6C3BE5A8B200}%27)%20and%20OwnerId/Id%20eq%20guid%27{6F7ADB65-89E6-4489-88EE-D59866EEC150}%27

Delete PostFollow Record to Unfollow

DELETE https://CRMORG.crm8.dynamics.com/api/data/v9.0/postfollows(5475f70e-14a6-ea11-a812-000d3a0a82c6) HTTP/1.1

Hope this helps! PowerPlatform My Friend!