Activity Forums Salesforce® Discussions How to get "mentionSegmentInput.id" in Salesforce Chatter?

  • chanchal kumar

    Member
    August 8, 2018 at 2:13 pm

    Hello Shradha,

    ID of the user or group to mention. To mention a user, use either id or username. You can’t include both.

    To mention a group, you must use id.

    • This reply was modified 5 years, 8 months ago by  Forcetalks.
  • shariq

    Member
    September 18, 2018 at 10:35 pm

    Hi,

    I this code will explains thing you want -

    List<AccountTeamMember> list_objAcctmem = [SELECT UserId, AccountId, IsDeleted, User.Name FROM AccountTeamMember WHERE AccountId =: objCase.AccountId LIMIT 25];
            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<ConnectApi.MessageSegmentInput>();
        
            textSegmentInput.text = 'Casenumber ' +objCase.CaseNumber+' with the status '+objCase.Status+' has breached SLA aggrement hours';
            messageBodyInput.messageSegments.add(textSegmentInput);
            
            
            // Mention a group.
            if(list_objAcctmem.size() > 0)
                {                
                    for(AccountTeamMember objAcctmem : list_objAcctmem )
                    {
                        ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
                        mentionSegmentInput.id = objAcctmem.UserId;
                        messageBodyInput.messageSegments.add(mentionSegmentInput);
                    }
                }
            feedItemInput.body = messageBodyInput;
            feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
        
            // Use a record ID for the subject ID.
            feedItemInput.subjectId = objCase.Id;
        
            ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(null, feedItemInput, null);

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos