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
Gary Payne 28Gary Payne 28 

How to limit Lookup Child records to only one active record?

Trying to create a validation rule that will fire if an active child record (FAR) already exists, (Parent=FA, Child=FAR has Lookup(FA)), and a new child record with the same picklist value is being created.  Following is my validation rule that is preventing creation of any new child record, whether or not one exists already:
         Active = True,
         ISPICKVAL(Role__c,"Joint Approver"),
Is there a way to perform a Count of a Role__c record so that the validation rule is looking for a Count > 1? Note that Role__c is a picklist with several values, like Survivor, Joint Approver, and Beneficiary. Only Survivor and Joint Approver values are limited to having only one active child record.
Pawel BorysPawel Borys
Hi, the easiest way to do this would be a roll-up summary field counting the number of child records with the selected picklist values. Except it looks like you have a lookup relationship and not master-detail so you can't use a roll-up here unless you convert the relationship.
In that case, I would use a simple before insert trigger or, if you're not a developer, a flow that would query the other child records of the parent, check the condition and set a flag on the record for a validation rule to trigger (since as far as I know a flow itself cannot prevent a record from being created)
Sara JenniferSara Jennifer
Planned streams are controlled by the Automated Process User, and not all Apex that would be protected with regards to a real client is protected with that client. ( We had this come up as of late with a planned stream summoning an Apex activity that pre-owned Auth.SessionManagement.getCurrentSession() - this tosses an exemption in a timetable stream, which isn't normal or recorded.