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
Jonathan Wolff 7Jonathan Wolff 7 

Block file types in salesforce

Hi, I would like to build a validation rule, trigger or anything like that so types like powerpoint or excel cant be uploaded. Can you tell me how to achive this?

Greetings
Jonathan
 
SwethaSwetha (Salesforce Developers) 
HI Jonathan,
Try the sample code for trigger mentioned in https://help.salesforce.com/articleView?id=000319977&type=1&mode=1
 
Trigger RestrictFile on FeedItem (after insert) {
Map<Id, FeedItem> contentversionIdToFeedItemMap = new Map<Id, FeedItem>();
for(FeedItem fi : trigger.new){
if(fi.type == 'ContentPost')
  contentversionIdToFeedItemMap.put(fi.RelatedRecordId, fi);
}
 for(ContentVersion cv : [SELECT Id, FileExtension,FileType FROM ContentVersion where Id IN :contentversionIdToFeedItemMap.keySet()])
{
  if(cv.FileType =='png')
  {
    contentversionIdToFeedItemMap.get(cv.Id).addError('File having this extension could not be attached,Please try some other extension.');
  }
 }  
}
Also see https://salesforce.stackexchange.com/questions/121123/how-to-restrict-file-type-in-standard-page-attach
If this information helps, please mark the answer as best. Thank you