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
Cody ValleCody Valle 

Require an attachment before workflow

I'm sure this is a very novice question, but is there a way to require an attachment on a form before allowing the user to select a field picklist value of closed won?
Best Answer chosen by Cody Valle
Andrew Wilkinson 2Andrew Wilkinson 2
Cody,

There is a way to do this but it wouldn't necessarily be easy. You cannot create a rollup summary field on Attachment. It would involve the following components:

1. Create a custom field on Opportunity(assuming from the picklist value you described). This custom field will store a roll up value from the Attachment object. It will need to be a number type. No decimals will be required.
2. Create a trigger on attachment. When the parent Id starts with the key prefix of the object you want to add the validation rule to(in this case 006 for Opportunity) you would need to create your own roll up functionality to get the total amount of attachments for this parentId and assign it to the new field above.
3. Create a validation rule on Opportunity that requires the roll up count to be greater than 0 when moving to Closed Won.

Here is a sample blog post that describes doign something similar to item 2: https://www.sundoginteractive.com/sunblog/posts/rollup-summary-with-a-lookup-field-salesforce.