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
rpatacarpataca 

Validation Rule

Trying to create a validation rule to limit the number of lookup relationships to an object. I have an Athlete object and a Group object. Each Group needs to be limited to 10 Athletes. Once I add an Athlete to salesforce I use a lookup field to relate the Athlete to the Group. But once Group has reached its limit of 10 Athletes, I want an error message to display. How would I go about doing this.

Any help is appreciated.

Thank you.


RickyGRickyG
I think you will be able to do this with a combination of rollup summary fields (available now) and relational business rules, also known as cross-object rules, to reference the rollup summary from the child Athelete field.  Relational business rules are scheduled for Winter '08.

Hope this helps.

Ron HessRon Hess
you could write an apex code trigger on the Athlete, which on update will query to see if the the new group is the 11th in that group, something like this SOQL in your trigger,

[select count() from athlete a where a.group__c = :Trigger.new[0].group__c]

this tries to find all athletes that have the same group id in their group pointer.

then if count >10, fail by calling addError()

i've probably overlooked something, but it's worth a try.
rpatacarpataca

I have looked for the apex code triggers but have not found them.

I have the professional edition.... is it available in my edition?

Thanks for your help guys, much appreciated.



RickyGRickyG
Unfortunately, you can only use Apex triggers with Unlimited Edition and Developer Edition. 

Sorry.

rpatacarpataca
Do I have any other options in going about doing this? I was thinking maybe a Validation Rule of some sort. Thanks for your assistance.
RickyGRickyG
The second message in this post provides a possible future alternative.