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
Egidio Caprino 9Egidio Caprino 9 

Validation rule on delete

Hello,

The right answer to this question
Universal Containers has built a recruiting application with 2 custom objects, Job Applications and Reviews that have a master-detail relationship. Users should NOT be allowed to delete review records after job application records have been approved. How would a developer meet this requirement?
seems to be this one
Use a validation rule in conjunction with a roll-up summary field
So we have a Job Application as Master object and Review as Detail one. The roll-up summary field is in the Master one for definition. A validation rule is executed only on INSERT and UPDATE operation, not on DELETE.

I do not see how to achieve the desired result using these two features. Do you know it?
Best Answer chosen by Egidio Caprino 9
KaranrajKaranraj
Egidio - You can achieve using validation rule itself. Add the following validation rule in the master object. The rollup summary field in the below example is SUM of all child record.
PRIORVALUE(RollupField__c ) > RollupField__c
The above validation rule going to throw error message in the master object when the RollupField(Sum of all child account) value is less than the prior value of that same field. If you delete the detail(child) record, it will delete record(before delete operation) which will intiate the  rollup summary field to calculate new value in the parent object which is going to be an update operation in Master object which will fire the Validation rule to execute and prevent the detail record to delete from the system. All this operations will be happend in the same execution process.

You are right validation rule is excuted only on Insert and Update operation not on DELETE operation but as per the above execution flow, its delete operation in detail object but its UPDATE operation in the master object. 

Try adding one validation rule in the Master object as mention above and try deleting the detail record.

Thanks,
http://www.karanrajs.com

All Answers

Neetu_BansalNeetu_Bansal
Hi Egidio,

You can achieve this by writing trigger on Review object.

Thanks,
Neetu
KaranrajKaranraj
Egidio - You can achieve using validation rule itself. Add the following validation rule in the master object. The rollup summary field in the below example is SUM of all child record.
PRIORVALUE(RollupField__c ) > RollupField__c
The above validation rule going to throw error message in the master object when the RollupField(Sum of all child account) value is less than the prior value of that same field. If you delete the detail(child) record, it will delete record(before delete operation) which will intiate the  rollup summary field to calculate new value in the parent object which is going to be an update operation in Master object which will fire the Validation rule to execute and prevent the detail record to delete from the system. All this operations will be happend in the same execution process.

You are right validation rule is excuted only on Insert and Update operation not on DELETE operation but as per the above execution flow, its delete operation in detail object but its UPDATE operation in the master object. 

Try adding one validation rule in the Master object as mention above and try deleting the detail record.

Thanks,
http://www.karanrajs.com
This was selected as the best answer
Egidio Caprino 9Egidio Caprino 9
Thank you Karanraj! Your answer is perfect!