Restricting the file types upload in salesforce chatter
To restrict the file types one option is to write a trigger on "Feeditem".
Developing the Trigger:
Open developer console ,go to "File"---> "New" --->"Apex Trigger".
From the pop-up give the name of the trigger and choose the sObject as "FeedItem" from the dropdown and hit "Submit"
Start Coding !!
//TRIGGER TO RESTRICT FILE TYPES ON CHATTER
trigger restrictFileType on FeedItem (after insert)
{
for(FeedItem fi : Trigger.new)
{
if(fi.ContentType == 'text')
fi.addError('You are not allowed to upload this kind of file');
}
}
You can further enhance the code by adding multiple file types in custom settings and refer it in the trigger instead of hardcoding in the trigger.
Happy Coding !!!!!!
To restrict the file types one option is to write a trigger on "Feeditem".
Developing the Trigger:
Open developer console ,go to "File"---> "New" --->"Apex Trigger".
From the pop-up give the name of the trigger and choose the sObject as "FeedItem" from the dropdown and hit "Submit"
Start Coding !!
//TRIGGER TO RESTRICT FILE TYPES ON CHATTER
trigger restrictFileType on FeedItem (after insert)
{
for(FeedItem fi : Trigger.new)
{
if(fi.ContentType == 'text')
fi.addError('You are not allowed to upload this kind of file');
}
}
You can further enhance the code by adding multiple file types in custom settings and refer it in the trigger instead of hardcoding in the trigger.
Happy Coding !!!!!!
Comments
Post a Comment