0

I need help building a Validation Rule to make sure "Notes and Attachments" are required before continuing to next stage. At least 1 attachment should be attached before the user can proceed to the next stage.

Can anybody help me create my first validation rule please?

  • 1
    Notes and attachments are not supported by validation rules, you have have to write an apex trigger. – Raul Sep 12 '18 at 18:53
1

The only way to do this with a validation rule (i.e., without writing code) is to maintain a count of Attachments on the Opportunity. Since the relationship between Attachment and Opportunity is not master-detail, this must be done with customization.

You can write a trigger to do this, but it's easier to do it declaratively by installing Declarative Lookup Rollup Summaries. You can build a rollup using DLRS with the parent object as Opportunity and the child as Attachment; rollup operation as COUNT; any SOQL parameters you need to include; and a target Number field on the Opportunity, such as Count_of_Attachments__c.

Once you do this and go through the activation process for DLRS, including setting the rollup to active and running it in real-time by having DLRS deploy its triggers (you'll probably also want to click Calculate to cover all existing Opportunities), you can write a validation rule on Opportunity something like this:

AND(Count_Of_Attachments__c = 0, ISPICKVAL(StageName, "YOUR_STAGE_NAME_HERE))

This is not a feature that you can get "out of the box". You're going to have to do some real customization to get there, but it's not difficult - you just need to go through several steps and effectively deploy these features to get to your objective.

  • Hi David, I appreciate your response (as always). I work in a D4/QA/Prod environment with multiple Admins, Testers, & Devs, so I can't really add DLRS. So if it's possible in DLRS, then it's possible without it right? Is there a way I can do it by just creating a new Validation rule and inserting relevant Fields/functions without DLRS? We want a requirement of a minimum of 1 attachment and after that attachment is there, they don't want users to have access to deleting it. In my last job, we would have just trained the users but this place is different. – Man Sep 13 '18 at 12:51
  • You don't have to use DLRS, but you do have to do more than create a validation rule. You'll need DLRS, or a trigger, or a complex set of Process Builder/Flow declarative automations to maintain the count on Opportunity of qualifying Attachments. – David Reed Sep 13 '18 at 12:53
  • Yeah they already shot down the Trigger approach... of_Attachments__c>0 -is all I have at the moment – Man Sep 13 '18 at 12:58
  • They need to be realistic about what it takes to develop this functionality! I would go talk to the senior dev/solution architect. – David Reed Sep 13 '18 at 13:04
  • Roger that, tyvm, i'll push for DLRS. We'll see how it goes. – Man Sep 13 '18 at 13:06

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.