[SalesForce] Can validation rule be used to check if same id already exists more than 3 times in a custom object

I have a custom object named PCS_Adoption_Detail__c which contains a master-detail lookup relationship field called Pet_Name__c which points to PCS_Pet__c custom object. Now I need to restrict the user to insert a record in PCS_Adoption_Detail__c only when if the lookup name already exists more than 3 times in this custom object.
i.e. when a user tries to insert a record i need to check whether the Pet_Name__c already exists more than 3 times or not in PCS_Adoption_Detail__c object and if it exists then i should show a validation message. Can this be done using validation rules? If not suggest me some other solution.

Best Answer

As mentioned by @Stygon I have used roll-up summary field to get the count and used a validation rule to show message if the count exceeds 3.

Related Topic