ABSYZ ABSYZ

  • Home

    Welcome to ABSYZ

  • About us

    Who We Are

  • Our Expertise

    What We Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Chatter Feed Migration in salesforce

Home / Article & Blogs / Chatter / Chatter Feed Migration in salesforce

Chatter Feed Migration in salesforce

By kumarkankari inChatter, Salesforce

This Blog gives you a brief understanding of how to post a chatter feed from child records feed to parent Record feed with “@mention” tag in Salesforce. This describes that when ­ever we post some information on the Child record feed it should auto-populate on the parent record feed.

A mention is a “@” character followed by a user or group name. 

For Example If we have two contacts related with the Account, enter the feed in contact1 as “@k kumar Hello Absyz1″ and contact2 as “@K KK Hello absyz2″ these two feeds are populated in Related Account as Shown in the below figure.

 

Account Feed

For achieving this we are following these two steps.

1.Get the feed from child Records with @mention

 

Reference Links for Feed item: These links helps us to get the Feed item with the reference of feed elements. From Contacts Feed, we will get the “@mention” and “text” from the feed elements that are under the feed item body. Using the ConnectApi.MessageSegmenttype, we will get the mention user id and text message that was entered in the feed item post on the child record.

https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_responses_feed_item.htm

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_input_messageSegmentInput.htm

2.Posting the Feed to Parent Records with @mention.

For posting the feed item with @mention in a parent record feed we use below link for Reference:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_post_feed_element_mention.htm

Here,Feed Item Input request body includes a body property that is a Message Body Input request body. Where the Message Body Input request body includes a messageSegments property that has one Message Segment Input: Text request body and one Message Segment Input: Mention request body.

Here below code is developed to achieve the functionality.

Trigger Handler:

[sourcecode language=”java”]
public class ContactFeedItemHandler {
public static Boolean isFirstTime = true;
public static void contactFeedItemmethod(list feedList){
mapaccidmap =new map();
setcontactid = new set();
for(FeedItem fi:feedList){
contactid.add(fi.ParentId);
}
for(contact c :[select id,AccountId from contact where id in :contactid]){
accidmap.put(c.id,c.AccountId);
}
String Id;
String temp;
Integer x = 0;
for(FeedItem fitem:feedList){
for(ConnectApi.FeedElement f:ConnectApi.ChatterFeeds.getFeedElementsFromFeed(Network.getNetworkId(), ConnectApi.FeedType.Record,fitem.ParentId ).elements){
if (f instanceof ConnectApi.FeedItem) {

for(ConnectApi.MessageSegment fb:f.body.messageSegments){
if(x==0)
{
if (fb.type == ConnectApi.MessageSegmentType.Text)
{
temp=((ConnectApi.TextSegment)fb).text;
system.debug(‘Input Text::’+temp);
x=x+1;
}
if(fb.type == ConnectApi.MessageSegmentType.Mention)
{
Id=((ConnectApi.MentionSegment)fb).record.id;
system.debug(‘Input Id::’+Id);
}
}
}

}
}
}
ContactFeedmet(Id,temp,accidmap,feedList);
}
public static void ContactFeedmet(String Id ,String temp, mapaccidmap,list feedList){
//Id=id1;
//temp=temp1;
for(FeedItem fi:feedList){
ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();

messageBodyInput.messageSegments = new List();

mentionSegmentInput.id = Id; // Set @mention
messageBodyInput.messageSegments.add(mentionSegmentInput);

textSegmentInput.text = temp;
messageBodyInput.messageSegments.add(textSegmentInput);

feedItemInput.body = messageBodyInput;
feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
feedItemInput.subjectId = accidmap.get(fi.ParentId);//UserInfo.getUserId();
ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);
}
}

}
[/sourcecode]

contactFeedItemmethod() method is help to get account ids related to contacts and using with ConnectApi.FeedElement will get the feed item elements like body,mention,text segment and messageSegments.
messageSegments contains type of segments like mention, link, hashtag and Text etc.
contactFeedItemmethod() here we are using variables like Id & temp.
Where, Id is used to get the @mention user id and temp is used to get the text from the feed item body of child. We are using connect Api to post the feed item.
contactFeedmet() method is used to post the chatter feed into parent record. Here we will map the Id to the mentionSegmentInput and temp to textSegmentInput.

accidmap.get(fi.ParentId) is used to map the parent Record Id to subjectId.

Trigger :

[sourcecode language=”java”]
trigger ContactFeedItemTrigger on FeedItem (after insert) {
if(Trigger.isInsert && Trigger.isAfter){

if(ContactFeedItemHandler.isFirstTime)
{
ContactFeedItemHandler.isFirstTime = false;
ContactFeedItemHandler.contactFeedItemmethod(trigger.new);

}
}
}
[/sourcecode]

OutPut:

Here, we achieved how to post the related contacts feed into Parent account feed.

Please refer Screenshots:

 

Contact 1 with feed item

 

contact2 with the feed item

 

Account with related contacts feed items.

 

Chatter FeedChatter Feed MigrationSalesforce Chatter
37
Like this post
2 Posts
kumarkankari

Search Posts

Archives

Categories

Recent posts

Significance of UI/UX Design

Significance of UI/UX Design

Cyber-security in an uncertain world

Cyber-security in an uncertain world

The world of AR and VR

The world of AR and VR

The in-and-out of ML

The in-and-out of ML

Future of Mobility

Future of Mobility

  • Previous PostHighlights Of Spring'19 Release Notes : Part I
  • Next PostIntroducing: Lightning Web Components

Related Posts

REST API call from Einstein Analytics Dashboard
Apex REST Salesforce Salesforce Einstein Wave Analytics

REST API call from Einstein Analytics Dashboard

Create/Update Salesforce Picklist definitions using metadata API
Integration Metadata API Salesforce

Create/Update Salesforce Picklist definitions using metadata API

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo
  • Home
  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

ABSYZ Software Consulting Pvt. Ltd.
USA: 49197 Wixom Tech Dr, Wixom, MI 48393, USA
M: +1.415.364.8055

India: 6th Floor, SS Techpark, PSR Prime, DLF Cyber City, Gachibowli, Hyderabad, Telangana – 500032
M: +91 79979 66174

Copyright ©2020 Absyz Inc. All Rights Reserved.

youngsoft
Copy