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
B2AB2A 

cross object referencing (for validation rule)

Hello All, i have the following use case:

 

Before saving a record (custom object), with a lookup field to a Contact,I need to check whether the contact already has one of these records created and associated to it.  In other words, I want to enforce that the contact record allows one record from a custom object created for it, else a validation rule should say "You have already created a 'custom object record entry for this contact."

 

Any idea whether this can be done via validations or apex triggers?

 

Thanks for any suggestions.

 

B2A

Steve :-/Steve :-/

What is the relationship between the Contact record and the Custom Object?  If it is a Master-Detail relationship thne you can create a custom Roll-Up Summary field on the Contact that counts the number of Child Records associated to the Contact.  Then create a Validation Formula that throws an error if the Count of Child records > 1 when a user tried to create a second Child record.

 

If the relationship is not Master-Detail then I think you have to go the Apex Trigger route, and I'm afraid I can't help you there.

Message Edited by Stevemo on 02-02-2010 12:22 AM