I have the requirement to create a validation rule that only allow you to set the status in closed won if a file is attached to the opportunity. To achieve this, I have created a custom field which is a counter and a custom trigger on ContentDocumentLink object which update that counter. I have tested it in my sandbox and works great but when I go in production and I try to add the file to the opportunity I get the error: Can't add 1 file to Opportunity.

I found this article: https://help.salesforce.com/s/articleView?id=000381870&type=1 where it says that the error is caused because of the custom trigger, and that is true because if I disable the trigger I can add files again.

I don't understand why in the sandbox works well and not in production, I don't know what I am missing. Any idea?

Due we can't create flows on CDL object and my trigger doesn't want to work, any other idea to achieve my requirement?

Thanks in advance

  • Did you go through the other things mentioned on that post? E.g. checking the required field on Content Version object? Commented Oct 17, 2022 at 10:14
  • Yes I do, in fact I have no custom fields on Content Version object
    – Jav
    Commented Oct 17, 2022 at 10:17
  • Ok, and no validation rules either, and sufficient file storage available? There must be another difference between the orgs then. But hard to tell exactly what/where.. Commented Oct 17, 2022 at 10:22
  • Yes, there is no validation rules on Content Version and the storage is in 1%... I will continue my research...
    – Jav
    Commented Oct 17, 2022 at 10:35
  • I finally solved that. I deactivated the CDL trigger in the sandbox and upload in production via changeset to deactivate that trigger in production, and then I activate the trigger in production via workbench deploy and magically I was able to attach files to the opportunity. I keep the Clairbois answer as best because is the best technical solution to my problem. Thank you all.
    – Jav
    Commented Oct 21, 2022 at 12:49

1 Answer 1


Since it's hard to tell exactly what is causing this (probably a difference between the environments), an alternative could be to build the entire logic into your Opportunity Trigger.

I.e. before update (to Closed Won) do a query on ContentDocumentLink having that Opportunity as parent id. If the query returns anything, do an addError() on the Opportunity in the trigger.

Maybe this is even better practice, because it doesn't require any DML and only requires 1 SOQL query at the time of closing the opportunity.

  • Thanks, I think I will go with this approach for now because I don't know what might be different between the environments that makes the trigger not work in CDL and I can't find much more info about it.
    – Jav
    Commented Oct 18, 2022 at 8:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .