Posted in Apex

How to use Connect API in Apex

Using Connect Api , we can access the chatter post and delete the posts using apex.

Scenario: How to post an announcement to a community

Using “ConnectApi.Announcements” class , we can create/update/read/delete the announcements.


Post an Announcement:


public static ConnectApi.Announcement postAnnouncement(String communityId, ConnectApi.AnnouncementInput announcement)

CommunityID — String
announcement — ConnectApi.AnnouncementInput object
Return type:


* Posting an announcement to community using ConnectApi namespace.
* Includes convenience methods to:
* – Post Chatter @-mentions, rich text, and inline images with Apex code.
* – Take a feed item or comment body and return an input body that matches it.
* This is useful for when you want post an announcement and send emails to the users.
* This class works with API version 32.0 and later.


public class postingAnnoucement{

* Creating an Announcement using ConnectApi.Announcement
* @param – None
* @return – Announcement

public ConnectApi.AnnouncementInput myAnnouncement(){
//Creating an announcement
ConnectApi.AnnouncementInput newAnnouncement = new       ConnectApi.AnnouncementInput();
newAnnouncement.expirationDate=; // Announcement Expiration Time, usually it will be expire on end of the day.
return newAnnouncement;


* Posting an Announcement on community using ConnectApi.Announcement
* @param – None
* @return – Void

public void postAnnouncement(){

ConnectApi.AnnouncementInput input=myAnnouncement();
ConnectApi.Announcement myfinalannouncemnt=                ConnectApi.Announcements.postAnnouncement(‘communityid’, input);




Next time will see you with some other interesting topic, Thank you.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s