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}"/> 
</aura:component>

------------------------------------------------------------------------------------------------

({
    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());
         }
      });
       $A.enqueueAction(action);
     }

})
----------------------------------------------------------------------------------------------------
public class chatterpost {
 @AuraEnabled
public string body { get; set;}
 @AuraEnabled public string userID { get; set;}
  @AuraEnabled
public static void postFeed(){
FeedItem post = new FeedItem();
//post.ParentId = userID;
//post.Body = body;
insert post;
}
 @AuraEnabled
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.
Thanks