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
Davide Filippi 10Davide Filippi 10 

Prevent user from upload attachment

Hi all,
I builded a Portal community and I need to permit Customers to upload files in "Note and Attachment" of Cases, but NOT in the other objects.

I can't just hide them from page layout because I need to let Customer download them, just not the upload.
How can i fulfill the requirements?
I tried with a trigger on Attachment but it didn't work


Hi Davide,
If I am not wrong then your requirement is that only attachment from case object is created so I think you can write trigger for this 
trigger triggerValidationForOnlyCase on Attachment (before insert,before update) {
      for(attachment att :{
       // check if parentid is not from case object with starting id 500
         if(att.parentid !=NULL && !String.valueOf(att.parentid).trim().startsWith('500')){
            att.parentid.addError('you can not insert attachment for this object');  

the above trigger will stop you to attachment for other objects except the case .
please mark as best answer if this was helpful else let me know.  

Thank you 
Avaneesh Singh
Software Developer 
Davide Filippi 10Davide Filippi 10
Unfortunatly it doesn't seem to work. The upload  from community is still effective