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
BrokenBirdBrokenBird 

Limiting related list

I have a lookup relationship between Object A and B, in object A I have a lookup field, while in Object B I have a related list.

 

I would like to be able to limit the number of Object A that reference Object B to 3, how can this be done?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
jpizzalajpizzala

You can use the addError() method

All Answers

jpizzalajpizzala
You can create an Apex trigger that will prevent any new records from being added to Object B as long as there are 3 Object A records already listed.
BrokenBirdBrokenBird
Ok but how do I return an error message to the end-user?
jpizzalajpizzala

You can use the addError() method

This was selected as the best answer
BrokenBirdBrokenBird
Thanks!!