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
KRISH9KRISH9 

Am trying to deleting feeds from the chatter the correponding records are also deleting.......

When ever am inserting record into "Emp_7_10__c" this custom object am inserting follow on the chatter. But i want to delete those follow from the chatter. But when am deleting follow from the chatter the corresponding records also deleting.

 

Any one give idea how to delete only follows on the chatter.

 

the following code am using to insert follow on the chatter:

-------------------------------------------------------------------------------


trigger SendNotification on Emp_7_10__c (after insert)
{
 if( Trigger.isInsert)
 {
  for (Emp_7_10__c e : Trigger.new)
  {
   if ( e.Id != null)
   {
    FeedItem post = new FeedItem();
    post.ParentId = e.Id;
    post.Title = e.Name;
    post.Body = 'My custom Chatter Notification';
    post.LinkUrl = 'google.com';
    insert post;    
  }
  }
 }
}

=====================================================================

The following code am trying to delete follow from the chatter. But records also deleting from the object.

 

Emp_7_10__c[] emp = [select Id from Emp_7_10__c];
delete emp;

BharathimohanBharathimohan

Hello Krish,

 

If you are trying to delete the Following subscription, you need to delete the Ids of the EntitySubscription Object.

-----------------------------------------------------------------------

List<EntitySubscription> es = [Select Id, ParentId, SubscriberId, CreatedById, CreatedDate FROM EntitySubscription WHERE ParentId=recordId and SubscriberId=userId];

 

delete(es);

 

-----------------------------------------------------------------------

 

recordId - SFDC recordId which User is Following (can be any object like Account,Contact,Emp_7_10__c etc.,)

userId -  is the SFDC User Id of the User who is following the record

 

 

Refer to this LINK for more details.

 

 

Regards,

Bharathi
Salesforce For All

 

Mrk this post as solved, if it helps you