You need to sign in to do that
Don't have an account?
![XIO XIO](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Assistance with FeedItem Apex Trigger
Hello!
We have the trigger below that if an attachment is deleted from Chatter Feed, certain profiles will recieve the error message. I need assistance in updating the trigger to only fire on a certain object (Documents_Manager__c). Currently the trigger is firing on all objects. The trigger is also currently blocking the System Administrator profile for testing testing purposes but we would like to add serveral profiles to the block list as well. Thank you in advance!
We have the trigger below that if an attachment is deleted from Chatter Feed, certain profiles will recieve the error message. I need assistance in updating the trigger to only fire on a certain object (Documents_Manager__c). Currently the trigger is firing on all objects. The trigger is also currently blocking the System Administrator profile for testing testing purposes but we would like to add serveral profiles to the block list as well. Thank you in advance!
trigger ChatterDeleteBlocker on FeedItem (After Delete) { User u = [SELECT id,ProfileId,Profile.Name FROM User WHERE id = :UserInfo.getUserId()]; for(FeedItem fi : trigger.old) if(fi.type == 'ContentPost' && u.Profile.Name == 'System Administrator') fi.addError('You do not have the permissions to delete files from chatter feed'); }
All Answers
You need to modify your code like this. It will ensure that the validation runs only on the Documents Manager object. Also, include the other profile names as seen in the code below.
Kindly mark it as an answer if that resolves your query !
Thank you for the quick response! I tried your code but users not included in the IF statement are receiving the error below:
I also updated the code a bit to not equal (!=) certain profiles and users instead of blocking certain profiles. See below:
Basically, the code is blocking all users (except the profiles and users in the IF statement) from deleting attachments only (no posts) from a specific custom object.