Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
TriggerOnAttachment
trigger AttachmentTrigger on Attachment (before insert) {
set<String> setExtNotAllowed = new set<String> {'exe','dll'};
for (Attachment attachment :Trigger.new) {
String strFilename = attachment.Name.toLowerCase();
List<String> parts = strFilename.splitByCharacterType();
if(setExtNotAllowed.Contains(parts[parts.size()-1])) {
attachment.addError('File with extension exe or dll could not be attached!!');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment