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
kittu9kittu9 

Not allow to delete records from the Related list

I have two objects, Coat & Coat Line Item. These two objects having master-details relation ship

 

1) Coat is Master object

2) Coat Line Item is detail object.

 

Coat object is having one field "status". If status = "Approved" the records in the related list recors can not be deleted.

Let say "Sample" is record in "Coat object" and it is having 100 records in the "Coat Line Item" (Detail object) related list.

 

If the "Sample" record, Status="Approved". If any one deleting any record from the related list, does not allow to delete the record of the related list.

 

How to achieve this functionality? In how many ways we can achieve this functionality?

I hope by using triggers we can do. But am not sure.

Please give your ideas how to achieve this functionlity either by using coding & configuration (Both the ways)

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Nazeer AhamedNazeer Ahamed

Include NOT( ISNEW()  ).

 

Like


AND( NOT(ISNEW()), ISPICKVAL( Status__c ,'Approved') , ISCHANGED( No_of_Employees__c ) ,true )

 

It should be fine now !!!

 

All Answers

liron169liron169

Write trigger on the son object (in delete), checking if the status in the parent is Approved, than use function addError to the object. It will block the deletion

kittu9kittu9

with out writing code is there any chance to do this functionality with Configuration???

kittu9kittu9

I have two objects, Coat & Coat Line Item. These two objects having master-details relation ship

 

1) Coat is Master object

2) Coat Line Item is detail object.

 

Coat object is having one field "status". If status = "Approved" the records in the related list recors can not be deleted.

Let say "Sample" is record in "Coat object" and it is having 100 records in the "Coat Line Item" (Detail object) related list.

 

If the "Sample" record, Status="Approved". If any one deleting any record from the related list, does not allow to delete the record of the related list.

 

How to achieve this functionality? In how many ways we can achieve this functionality?

I hope by using triggers we can do. But am not sure.

Please give your ideas how to achieve this functionlity either by using coding & configuration (Both the ways)

 

one way is through trigger. Is there any way to achieve this functionality through Configuration with out using code????

Nazeer AhamedNazeer Ahamed

Create rollup summary field in parent object and get count of child objects.

Create validation rule in parent object, if the status is approved and Rollup count is changed throw some message!!

 

Hope it works !!!

kittu9kittu9
Thank you so much Nazzy. It is working with this rollup summary and validation rule. :)
Nazeer AhamedNazeer Ahamed

Kudos, I am glad.

kittu9kittu9
Nazzy,

It is working when am deleting records from the related list it is not allowing to delete records.

Now am trying to insert new record, I am getting the same validation rule error . It is not allowing me to create new records :(

The following validation rule i kept.

AND( ISPICKVAL( Status__c ,'Approved') , ISCHANGED( No_of_Employees__c ) ,true )

Not able to insert new records.
Dipa87Dipa87

In that case,

 

You can check the new value and the prior value.If the roll up summary field value increases(i.e new record created) then dont process the logic and if it decreases(i.e record deleted ) then process the logic.

 

 

Nazeer AhamedNazeer Ahamed

Include NOT( ISNEW()  ).

 

Like


AND( NOT(ISNEW()), ISPICKVAL( Status__c ,'Approved') , ISCHANGED( No_of_Employees__c ) ,true )

 

It should be fine now !!!

 

This was selected as the best answer