---
schema_version: "1"
id: 0d9bd281b1628b00b4bb3e6ef8d2fc0f4d79d22570c945c7bba0aa1b460f7c38
title: Edit a Feed Element
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/connectapi_examples_edit_feed_element.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_edit_feed_element.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 34ae0f60db5c03582bab6ee3c7b90cc3faa810cce40b224f94c9ea01b359f447
description: Call a method to edit a feed element.
---
# Edit a Feed Element

Call a method to edit a feed element.

Call [updateFeedElement(communityId, feedElementId, feedElement)](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_ConnectAPI_ChatterFeeds_static_methods.htm#apex_ConnectAPI_ChatterFeeds_updateFeedElement) to edit a feed element. Feed items are the only type of feed element that can be edited.

String communityId = Network.getNetworkId();

// Get the last feed item created by the context user.
List<FeedItem> feedItems = \[SELECT Id FROM FeedItem WHERE CreatedById = :UserInfo.getUserId() WITH USER\_MODE ORDER BY CreatedDate DESC\];
if (feedItems.isEmpty()) {
    // Return null within anonymous apex.
    return null;
}
String feedElementId = feedItems\[0\].id;

ConnectApi.FeedEntityIsEditable isEditable = ConnectApi.ChatterFeeds.isFeedElementEditableByMe(communityId, feedElementId);

if (isEditable.isEditableByMe == true){
    ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
    ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
    ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();

    messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

    textSegmentInput.text = 'This is my edited post.';
    messageBodyInput.messageSegments.add(textSegmentInput);

    feedItemInput.body = messageBodyInput;

    ConnectApi.FeedElement editedFeedElement = ConnectApi.ChatterFeeds.updateFeedElement(communityId, feedElementId, feedItemInput);
}