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
Varun Sachdeva 29Varun Sachdeva 29 

Validation rule to link Opportunity stage to Custom object

I have created a custom object for attachment with Opportunity as the parent. I want to link opportunity stage to this object. One should be able to mark the stage as closed won only when the custom object has some attachment. Need a validation rule for this. Have tried this script
AND(ISPICKVAL(StageName,"Closed Won"),  ISBLANK($ObjectType.OpportunityAttachment__c.Fields.Name))
It shows no syntax error, but does not function while marking the stage as closed won
VamsiVamsi
Hi Varun,

You can't validate whether a Opportunity is having child records or not using validation rules. You need to write a Trigger on opportunity with before update and then query the attachments related to each Opp and then verify if its greater than 0  allow to update else throw error.

Hope this helps ...!!!
Varun Sachdeva 29Varun Sachdeva 29
Hi Varun
Thanks for the reply. We have a similar validation rule requiring opportunity to have product line item in order for it to be marked closed won. Any reason why cant the same be applied for the custom object.