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
shalini sharma 24shalini sharma 24 

Posting to chatter on the click from lightning button in lightning componenet

I have a lightning:inputRichText and a lightning:button named "Submit" on a lightning component. To start with, i have also created another ui:outputText to display the logged in user id. On the click of this button, i would like to post the text eneterd in the rich text area to the mentioned logged in  user id's chatter.
<aura:component controller="chatterpost" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:appHostable,force:hasRecordId,force:lightningQuickAction" access="global">
     <aura:attribute name="myVal" type="String" />
     <aura:handler name="init" value="{! this }" action="{! c.init }"/>
     <lightning:inputRichText value="{!v.myVal}" />
    <aura:attribute name="myText" type="string" />
    <ui:outputText class="field" value="{!v.userId}" />
    <lightning:button variant="brand" label="Send" onclick="{!c.init}"/> 


    init: function(cmp) {
        cmp.set('v.myVal', '<b>Hello!</b>');
        var userId = $A.get("$SObjectType.CurrentUser.Id");
        cmp.set('v.userId', userId);
        var action = cmp.get("c.getUserId");
        action.setCallback(this, function(response){
        var state = response.getState();
        if (state === "SUCCESS") {
            cmp.set("v.userId", response.getReturnValue());

public class chatterpost {
public string body { get; set;}
 @AuraEnabled public string userID { get; set;}
public static void postFeed(){
FeedItem post = new FeedItem();
//post.ParentId = userID;
//post.Body = body;
insert post;
public static String getUserId() {
    return userinfo.getUserId();
I dont have much knowledge in lightning so its the rough code that i was trying to build up.Can anybody suggest me the solution to this.