1

Scenario:

I want the attachments object to take only certain types of attachments. For example lets say 'pdf, .html, .doc' only. I am well aware if I write a Visualforce page and an apex class I can configure this in <apex:inputfile>. Can this be achieved by without writing any piece of code? This has to be totally configurable i.e. giving the manager full rights to choose which attachment formats should work.

I have tried to find but haven't found anything useful so far. Has anyone worked this around?

Rationale behind no code: The solution manager will be a non-programmer so I want to achieve this functionality via configuration and not customization.

Any helps are appreciated.

1

You can create a "Custom Setting" to allow non-coding configuration of which types are allowed. After that, you can create a trigger to determine if the system should allow the upload to continue.

I would recommend a "list" setting, because you can actually get them all in one step. Here's some code:

trigger LimitAttachments on Attachment (before insert) {
    Map<String, CustomSetting__c> settings = CustomSetting__c.getAll();
    for(Attachment record: Trigger.new) {
        if(!settings.containsKey(record.contentType)) {
            record.addError('This type of upload is forbidden by the administrator.');
        }
    }
}

Of course, there's other ways of going about this. You'll also probably want to write an administration screen to allow administrators to add/remove values from the list without using the setup screen. For example, the page could accept a file upload of a "sample" to allow, so that the correct mime type will automatically be collected without the administrator needing to know if he should be using "text/plain" or "application/vnd.ms-excel".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.