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
arun sfdcarun sfdc 

Hi Guys, I have requirement to set the limit for uploading a file in salesforce

I have requirement like this, user can upload only one file from related list of files.
if user trying to add more than one file he will get an error like can't upload more than one.

Please give me answers as soon as possible.

Thanks advance...
Ravi Dutt SharmaRavi Dutt Sharma
Hi Arun,

You can write a before trigger on Attachment object and check whether there are already any attachments under your parent record. If there are attachments already present, then use addError method to stop the upload.

Similar example is provided at the link (http://www.sfdcpoint.com/salesforce/trigger-on-attachment-in-salesforce/)

Please mark this as the best answer if it resolves your issue. Thanks.
arun sfdcarun sfdc
Hi Ravi,

I was asked about files object not attachement object and give me advice for this. please