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
Akansha RangariAkansha Rangari 

Validation rule for Self Lookup , hitting recursively

Hi, Could you please help me written validation rule.

I'm having object 'Vehicle' which is having field 'Lock'. And there is another object name as 'CLIN' having lookup relationship to Vehicle, also there is self relationship between CLIN object.

Validation is written on 'CLIN' object. If 'Vehicle' record is locked , can not create/Update CLIN record.

Also After trigger is working on 'CLIN' object, which rollups fields to the same parent record.
Currently, I'm creating CLIN selecting self lookup relationship field and that selected CLIN's Vehicle is locked. So, when I'm creating this record I am getting validation error.

I need a validation that checks only Current CLIN's Vehicle is locked excluding the self lookup CLIN's Vehicle record is either locked or not.

Thanks in advance

Shivdeep KumarShivdeep Kumar
Hi Akansha,
firstly let me tell you what I got from your requirement-
There are 2 object, Vehicle and CLIN. Vehicle is the parent of CLIN and CLIN has a self lookup relation as well.
Vehicle has "Lock" field, when this field is true after that no one can create OR update the child record of CLIN object. PLUS after locking the child record of CLIN, there is a "After Insert & After update trigger" on CLIN object which update the self lookup parent record (CLIN).
AND now you want the validation rule that if Vehicle.Lock__c = true, no one can create/update the CLIN child record but CLIN self child record can update it by trigger.

if I am on the same page, here are the two solutions-
1- Validation Rule -- AND(Vehicle__c.Lock__c, CLIN__c.ParentId__c = null, NOT(ISCHANGED(CLIN__c.RollupField__c))
2- You can by pass the trigger logic by using the custom setting. Use the custom setting in validation rule and make the true & false in trigger on updating the CLIN parent object field. 

Please let me know if you find this as your solution.

Thanks,
Shivdeep Kumar