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
Nish321Nish321 

Limiting the ability to add related list items

How do I restrict the user to add multiple related list items? As per the requirement, User should not be able to add more than one related list item. Any suggestions on this would be appreciated.

Thanks,
Ramshah
Viral SodhaViral Sodha
I have implemented this using the following: 
Method 1: If its a master-detail relationship, add a rollup summary field to "count" related list items. Then place a validation rule / java script on custom button that throws an error when related list item count > 1. 
Also possible you can use:
Method 2: Could write a trigger that checks the count of related list items and throws an error if count > 1

Hope this helps! 
Best, 
Viral S.
Nish321Nish321
Thank you Viral for the response.  This is a lookup relationship. So do I have to go for trigger?
Viral SodhaViral Sodha
I see. Well you could still do it using a validation rule. You will need to maintain a numeric "count" field and update it by "+1" everytime a related list item is added! Then in the validation rule, if count > 1, give error. This would be the easiest way of achieving this. Hope this helps! 

Best, 
Viral S. 
Nish321Nish321
Could you please help me out with the validation rule?