ABSYZ ABSYZ

  • Home

    Home

  • 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
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
93
Like this post
2 Posts
kumarkankari

Search Posts

Archives

Categories

Recent posts

All About The OmniStudio FlexCards

All About The OmniStudio FlexCards

Boost Customer Experience With Repeater Widget in CRM Analytics

Boost Customer Experience With Repeater Widget in CRM Analytics

Enhance Insights Using Custom Tooltips In CRM Analytics

Enhance Insights Using Custom Tooltips In CRM Analytics

Net zero as a Service In CPG Industry

Net zero as a Service In CPG Industry

How Do We Import an External Library into Salesforce Lightning?

How Do We Import an External Library into Salesforce Lightning?

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

Related Posts

All About The OmniStudio FlexCards
OmniStudio Salesforce

All About The OmniStudio FlexCards

Boost Customer Experience With Repeater Widget in CRM Analytics
CRM Analytics Salesforce

Boost Customer Experience With Repeater Widget in CRM Analytics

Enhance Insights Using Custom Tooltips In CRM Analytics
CRM Analytics Salesforce

Enhance Insights Using Custom Tooltips In CRM Analytics

How Do We Import an External Library into Salesforce Lightning?
Lightning Salesforce

How Do We Import an External Library into Salesforce Lightning?

Leave a Reply (Cancel reply)

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

*
*

ABSYZ Logo

INDIA | USA | UAE

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

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT