Activity Forums Salesforce® Discussions How to create Chatter post from Salesforce Apex?

  • shariq

    Member
    September 22, 2018 at 5:06 pm

    //Adding a Text post
    FeedItem post = new FeedItem();
    post.ParentId = oId; //eg. Opportunity id, custom object id..
    post.Body = 'Enter post text here';
    insert post;

    //Adding a Link post
    FeedItem post = new FeedItem();
    post.ParentId = oId; //eg. Opportunity id, custom object id..
    post.Body = 'Enter post text here';
    post.LinkUrl = 'http://www.someurl.com';
    insert post;

    //Adding a Content post
    FeedItem post = new FeedItem();
    post.ParentId = oId; //eg. Opportunity id, custom object id..
    post.Body = 'Enter post text here';
    post.ContentData = base64EncodedFileData;
    post.ContentFileName = 'sample.pdf';
    insert post;

  • Parul

    Member
    September 22, 2018 at 6:07 pm

    public class chatterpost {
    public string body { get; set;}
    public string userID { get; set;}

    public void postFeed(){
    FeedItem post = new FeedItem();
    post.ParentId = userID;
    post.Body = body;
    insert post;
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos