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
Anuj Kumar 29Anuj Kumar 29 

Want to restrict to delete the related list.

Hi All,
I want to restrict to delete a related list record while clicking on delete button. for example i am having a Project__c custom object in that i am having a related list of Assignment__c custom object. Now, if user try to remove the Assignment related list while clicking the delete button it should not remove.

Solution: I am trying to apply the trigger to restrict to delete the Assignment related list but not able to proceed coz. i am just a beginner in Salesforce and this is the work is pending on my name.
any solution will be appriciated.
Thanks,
Anuj

 

Ankur Saini 9Ankur Saini 9
Hi Anuj

try this:
 
trigger contactBeforeDelete on Contact(before delete){ 
for(Contact contact: trigger.old){ 
    if(contact.accountId != null){ 
        contact.addError('Hey! You are not authorized to perform this action.'); 
        } 
     } 
 }

Thanks
Ankur Saini
Sukanya BanekarSukanya Banekar
Hi Anuj,
If you don't want to give delete functionality of related list record then you should create custom related list.

1. Create standard visualforce page with same UI as related list.
2. Remove standard related list from page layout and drag and drop visualforce page on page Layout

Following is a code you can try:
<apex:page standardController="Account">

<apex:includeScript value="{!$Resource.jQueryPlugin}"/>
<script>
$(document).ready(function(){
    $('td.actionColumn').empty();
});
</script>

<apex:relatedList list="Contacts">    
</apex:relatedList>

</apex:page>