You need to sign in to do that
Don't have an account?
cjen
Chatter feed trigger validation to only post in a group feed
hi, we have a community and we do not want our commununity users to post to their own feed, rather in a group feed. Reason is because we monitor groups but don't follow individuals so might miss a post. So, i reserached in chatter forums and found this trigger, was told that it will do what we want.
I am not a coder, so can someone please reveiw the code and let me know if it will do what we want? And, I am having trouble locating out Community ID. I am assuming that NetworkScope is community ID???? so need help finding that too. Lastly, can someone help me with a unit test for this, please?
Thanks very much!!!
Sample Code:
trigger FilterOnChatterPost on FeedItem (before insert) {
for (FeedItem feeditems: trigger.new)
{
if (string.valueOf(feeditems.ParentId).startsWith('005') && feeditems.NetworkScope== '0DBB000000008t2OAA')
{
feeditems.addError('You are only allowed to post the message to Discussion Groups’);
}
}
}
I am not a coder, so can someone please reveiw the code and let me know if it will do what we want? And, I am having trouble locating out Community ID. I am assuming that NetworkScope is community ID???? so need help finding that too. Lastly, can someone help me with a unit test for this, please?
Thanks very much!!!
Sample Code:
trigger FilterOnChatterPost on FeedItem (before insert) {
for (FeedItem feeditems: trigger.new)
{
if (string.valueOf(feeditems.ParentId).startsWith('005') && feeditems.NetworkScope== '0DBB000000008t2OAA')
{
feeditems.addError('You are only allowed to post the message to Discussion Groups’);
}
}
}
The NetworkScope field has the following description in Salesforce Help (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_feeditem.htm):
Specifies whether this feed item is available in the default community, a specific community, or all communities. This field is available in API version 26.0 and later, if Salesforce Communities is enabled for your organization.
NetworkScope can have the following values:
- NetworkId—The ID of the community in which the FeedItem is available. If left empty, the feed item is only available in the default community.
- AllNetworks—The feed item is available in all communities.
Note the following exceptions for NetworkScope:So what the trigger is currently doing is the following:
What YOU want to do is create a list of groups (CollaborationGroup) your users MAY post to and check if the FeedItem is for one of those groups. If not, add the error.
A small example of how this could work:
The test class would be something like this:
Of course you will have to change a few things to make this work for your situation, but the basics should be covered now.
I hope this helps!
Happy coding and best regards,
Martijn Schwärzer