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
newbie2010newbie2010 

Create Chatter Post from user input

I have created a custom VF Page generated by a custom button on the account page that creates a "log a call" activity as a completed task.  The comment field is the only thing that shows on this VF Page so all they have to do is enter the details of the call and the rest of the details are done internally, i.e. related to account where button was selected, inserts subject, date, type,etc.  The account info is pulled from the URL associated with the button.

 

Is it possible to create a chatter feed on the related account from what the user entered in the comment field?  Is there some documentation somewhere on how to accomplish this?

 

Thanks in advance for any help...

Best Answer chosen by Admin (Salesforce Developers) 
newbie2010newbie2010

I was able to get this to work, but not sure if it was coded correctly so any suggestions/best practices would be greatly appreciated.

 

This is only part of the extension class that I created to accomplish this, but it is the main part that created the feed...

 

    public PageReference Save()
    {
        FeedItem cpost = new FeedItem();
        cpost.ParentId = ApexPages.currentPage().getParameters().get('what_id');
        cpost.Body = task.description;
        try{
          insert(task);
          insert cpost;
          }
        catch(System.DMLException e){
          ApexPages.addMessages(e);
          return null;
          }