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
ddotddot 

How to limit names of @ mention on FeedComment Trigger

Hi,

I'm trying to write a trigger that will only allow a user in the community to be able to only see a certain list of users they can @ mention. So far I have following but it is not working:

trigger MentionFeedComment on FeedComment (before insert, before update) {

    List<User> listUserPlatform = [SELECT ID, Name FROM User WHERE Profile.Name <> 'ProfileA' OR Profile.Name <> 'ProfileB'];
    List<String> listNameUserPlatform = new List<String>();

    for(User u : listUserPlatform) {
        listNameUserPlatform.add('@'+u.Name);
    }

    for(FeedComment f : Trigger.new) {
    Boolean nameFinded = false;
    for(Integer i=0; i < listNameUserPlatform.size() && !nameFinded; i++) {
        if( f.CommentBody .contains(listNameUserPlatform.get(i)) ) {
            nameFinded=true;
            f.addError('You can\'t use mention');
        }
    }
}
}

Any help to point me in the right direction will be greatly appreciated. 
VinayVinay (Salesforce Developers) 
Hi,

Check below links which can help you on your implementation.

https://success.salesforce.com/answers?id=9063A000000ld8lQAA
https://success.salesforce.com/answers?id=9063A000000eAlZQAU
https://developer.salesforce.com/forums/?id=906F0000000kFh7IAE
https://success.salesforce.com/answers?id=9063A000000e46KQAQ
https://salesforce.stackexchange.com/questions/178223/can-i-disable-the-chatter-mention

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar