Slaesforce FAQ

how to create a post apex insert feeditem salesforce

by Mr. Guy Schuppe MD Published 2 years ago Updated 2 years ago
image

Apex Code 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; } } As you can see here we have used an object of the FeedItem class, which is used to post data to chatter.

Full Answer

What is feeditem in Salesforce?

FeedItem represents an entry in the feed, such as changes in a record feed, including text posts, link posts, and content posts. This object is available in API version 21.0 and later. This object replaces FeedPost. FeedItem | Object Reference for Salesforce and Lightning Platform | Salesforce Developers

How do I add a text post to a feeditem?

//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;

What version of Salesforce is the feedpost object available in?

This object is available in API version 21.0 and later. This object replaces FeedPost. FeedItem | Object Reference for Salesforce and Lightning Platform | Salesforce Developers Share your feedbackabout our new site.

How to add Salesforce Chatter posts with links to URLs and mentions?

You can refer the following example to add Salesforce Chatter posts with links, urls and mentions: public with sharing class ChatterUtils { // makes a simple chatter text post to the specified user from the running user public static void simpleTextPost (Id userId, String postText) { ConnectApi. FeedType feedType = ConnectApi. FeedType.

image

How do I create a Chatter post from Apex in Salesforce?

To enable chatter all we have to do is go to the Setup|Customize|Chatter|Chatter Settings and enable chatter. After that a new chatter tab will be visible in specific apps. However someone might be having a specific requirement about posting data on chatter from APEX code.

How do you insert a record into Apex?

How do I add a record to a custom object in Apex? To create new records in Salesforce, select the custom object where the form data should be saved. Then, map the Salesforce fields with the form fields. The Salesforce fields will load according to the object you select.

How do I post a Chatter in Salesforce trigger?

Its very simple. Just write a trigger on Salesforce object named "FeedItem". On Feeditem object "ParentId" is the field where you can link the account record with the chatter post. Hope it help!

How do I add Apex code to Salesforce?

Adding an Apex ClassFrom Setup, enter “Apex Classes” in the Quick Find box, then select Apex Classes and click New.In the class editor, enter this class definition: public class MyHelloWorld { } ... Add this method definition between the class opening and closing brackets. ... Click Save to save the new class.

What is insert in Apex?

Important. This example inserts three account records and updates an existing account record. First, three Account sObjects are created and added to a list. An insert statement bulk inserts the list of accounts as an argument.

How do I create a new record in SalesForce?

Create Records from Object Home PagesClick the object for the kind of record you want to create. For example, click Accounts if you want to create an account record.Click New.Select a record type if you're prompted.Enter values in the fields. ... Save your changes, when you finish entering values for your new record.

How do you post on Chatter?

0:041:11Let's learn to Post Something to Chatter @salesforce - YouTubeYouTubeStart of suggested clipEnd of suggested clipOnce you share your post you can find it by searching for take it to chatter. You also find anyMoreOnce you share your post you can find it by searching for take it to chatter. You also find any other post that was tagged hashtag take it to chatter. Click share or press ctrl + Enter.

How do I post to Chatter in process builder?

Choose “Post to Chatter” in “Action Type” and Choose “Chatter Group” in Post to then find the Chatter group which your org already have. Otherwise create a chatter group. Also Enter a Message like “New'Customer Direct' Account is created”. Step 6: Activate the process Builder.

How do I send a Chatter message in Salesforce?

Required Editions Click the Messages link on the Chatter tab, then click New Message in My Messages. Open a person's profile by clicking their name anywhere in Chatter, and then click Send a message. Click Send a message on a person's hover.

How do I create a custom object in Salesforce using apex?

Create a Custom ObjectLog in to your sandbox or Developer org.From your management settings for custom objects, if you're using Salesforce Classic, click New Custom Object, or if you're using Lightning Experience, select Create | Custom Object.Enter Book for the label.Enter Books for the plural label.Click Save.More items...

How do I start an Apex code?

Quick Start: Apex Coding for AdminsExecute Anonymous Blocks. ~10 mins.Create a BankAcct and CreateContactFromCan Class. ~5 mins.Instantiate an Object and Invoke a Method from Execute Anonymous. ... Create a List. ... Create a List FOR Loop. ... Use DML to Save sObjects to the Database. ... Create SOQL to Return Data to Apex. ... Create a Trigger.

How do you write a batch Apex?

To write a Batch Apex class, your class must implement the Database.Batchable interface and include the following three methods:start. Used to collect the records or objects to be passed to the interface method execute for processing. ... execute. ... finish.

Apex Code

As you can see here we have used an object of the FeedItem class, which is used to post data to chatter. All we have to do is enter the post body and parentId, and then insert the post. You can also provide your own id to the parentId which will result in the post being posted to your own profile.

VisualForce Code

In the Visualforce Code we have just got the data that we want to create a post on chatter. Once after entering the data, click on the post button and then quickly move to the chatter tab to see the updates.

Support

That’s all about creating a post on chatter through APEX, for any further queries feel free to add a ticket at:

shradha jain

You can refer the following example to add Salesforce Chatter posts with links, urls and mentions: public with sharing class ChatterUtils { // makes a simple chatter text post to the specified user from the running user public static void simpleTextPost (Id userId, String postText) { ConnectApi.FeedType feedType = ConnectApi.FeedType.UserProfile; ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput (); messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput> ();.

Naveen Naidu

Is that possible with batch.. I need to send chatter notifications when opp close it today.

Karthik J

Hi this code sends post to everyone, How to send post to particular person in chatter? Please tell me I need this.

image
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9