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
sfadm sfadmsfadm sfadm 

How to create a validation rule to deny all users creating new records except one?

I have a roll-up summary filed which is calculating the number of child records.

If the number of child records is greater than 2 I need to deny all users from creating new records except one.

I need to allow only one user / record owner to be able to create a third record.

I've created the following validation rule:
my_custom_rollup_field > 2 && $ObjectType.Child_Custom_Object__c.Fields.Owner__c <> 'owner.Id'
However that validation rule is not working.

Please advise what else I need in my validation rule to give the opportunity to only one user / record owner to be able to create a third record? ​​​​​​​
 
Best Answer chosen by sfadm sfadm
NagendraNagendra (Salesforce Developers) 
Hi,


Try this validation rule.
ISNEW() && (my_custom_rollup_field > 2 || OwnerId <> $User.Id)

Hope this helps.

Thanks,
Nagendra

All Answers

Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi sfadm

You need to create a validation rule on the object whoose record creation you wish to block.
So validation rule on child record would be as follows:

AND(PARENT_FIELD_NAME__r.ROLLUP_FIELD__c >=2 , ownerId != {USERID for which you wish to bypass validation} )

Cheers!!!!
NagendraNagendra (Salesforce Developers) 
Hi,


Try this validation rule.
ISNEW() && (my_custom_rollup_field > 2 || OwnerId <> $User.Id)

Hope this helps.

Thanks,
Nagendra
This was selected as the best answer
sfadm sfadmsfadm sfadm

@Syed Insha Jawaid 2

I've created a validation rule in the child objec the way you suggested but it is not working at all.

Even if only:

PARENT_FIELD_NAME__r.ROLLUP_FIELD__c >=2

It is still allowing my users to create third record.

Pleae advise how to create it in the parent object?

Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi sfadm

Could you please share the field level details and relationship of the object and current validation.
Just want to ensure if it is a custom rollup or not.

Cheers!!!