How do I generate an error when a comma or an apostrophe is included in the file name of an attachment using Groovy?
Here's a sample Groovy script that you can use in the Before Update trigger on the Opportunity object to check for characters such as commas and apostrophes in the file names of attachments.
def result = '';
def row = Attachment;
row.reset();
if (row.hasNext()) {
def currow = row.next();
def fileName = currow.getAttribute('FileName');
println("fileName" + fileName);
// check
def invalidChars = [",", "'", """];
def hasInvalidChar = invalidChars.any { fileName.contains(it) };
if (hasInvalidChar) {
throw new oracle.jbo.ValidationException("Error" + fileName);
}
}