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
LoserKidLoserKid 

post to chatter group using apex

Is it possible to post to a colaboration group via apex. i have a trigger on task that need to post to a group not all of chatter. Im most confused how i would handle the insert post command.

Best Answer chosen by Admin (Salesforce Developers) 
LoserKidLoserKid

Okay some posting my solution my self agian. @Top, you where correct original. The post.PartnetId must equlal the group ID. Salesforce is even crafty enough to add the user that posted it as well. However, my original issue did spawn from the fact that i was on the old API 20. For this to work you must be using API 21 and up. In this case im using 22 which i had to manually set in the meta.xml the Chatter Code Recipes #6 has a some great examples. Heres my cood. Thanks again Top.

 

trigger TaskToChatterGroup on Task (after insert, after update)

{

FeedItem post = new FeedItem();

 

post.ParentId = '0F9Q00000004DbmKAE';

post.Body = 'If this works im gonna be angry'; // And i was... super simple :D

 

insert post;

}

All Answers

TopalovichTopalovich

 

I'm not 100% on this, but wouldn't you simply make the CollaborationGroup.Id the ParentID for the FeedItem?

 

 

Mike

 

 

LoserKidLoserKid

First, thanks for a speedy reply. Unforuntly that did not work. i think the ParentId has to be a user that is a member of that group. 

 

FeedPost post = new FeedPost();

 

post.Type = 'TextPost';

post.ParentId = Userinfo.getUserId();

post.Title = 'Title of post';

post.Body = 'Body of post';

 

insert post;

 

that works perfect, except it post it out ot all Chatter and i want it to go to just a certion group. So far i have had no luck finding anyway to insert the post differently. maybe im missing a peice. But i do think i will have to have the ParentId as the users Id.

 

thanks

 

TopalovichTopalovich

My guys have done this, I just don't have ready access to the code so I'm going from memory.  A couple of thoughts:

 

1. Use FeedItem rather than FeedPost (FeedPost is being depricated from what I understand)

2. Instead of using the CollaborationGroup object for the ParentId, try the CollaborationGroupFeed object

 

 

Mike

LoserKidLoserKid

Still haveing issues however, my first attemps to use FeedItems were unsuccessful. i kept get the error that FeedItem was not a correct data type. After doing some digging it turns out that FeedItem is a newer API. Only APIs after 21.0 will be able to use FeedItem. So I tried to create a new Trigger in eclipse and i only have the option to create API 20.0. if anyone else comes across this issue open the .trigger-meta.xml and manually type in 22.0 in the APIs. Save All and there you go. it will push through and update in Salesforce. If you try to make the update in Salesforce it will not push it back to Eclipse. Hope this helps and is anyone has any suggestions or better yet... examples, please help. 

 

Thanks

Aaron

LoserKidLoserKid

Okay some posting my solution my self agian. @Top, you where correct original. The post.PartnetId must equlal the group ID. Salesforce is even crafty enough to add the user that posted it as well. However, my original issue did spawn from the fact that i was on the old API 20. For this to work you must be using API 21 and up. In this case im using 22 which i had to manually set in the meta.xml the Chatter Code Recipes #6 has a some great examples. Heres my cood. Thanks again Top.

 

trigger TaskToChatterGroup on Task (after insert, after update)

{

FeedItem post = new FeedItem();

 

post.ParentId = '0F9Q00000004DbmKAE';

post.Body = 'If this works im gonna be angry'; // And i was... super simple :D

 

insert post;

}

This was selected as the best answer
TopalovichTopalovich

That's a great point - this gap between the API version and the IDE version needs to be addressed ASAP.  Having to implement hacks to work around it is counterproductive.

 

Awesome that you found a solution!

 

 

Mike

 

 

keady@sfdckeady@sfdc

HI Topalvich,

 

I have the same requirement.  i followed below 2 suggestions but still no luck finding it working.

please share a piece of working code

Thanks in advance

venkata krishna reddy 1venkata krishna reddy 1
multiselect picklist - I have one multiselect picklist available values select on value the correspoing multi values are displayed in choosen List but I remove from the choosen list only one value removed but I want remove all corresponding values from choosen list. this is the actual task, can any body can help to over come this problem.
thanks