Skip to main content
1 resposta
  1. 9 de fev. de 2018, 10:22
    Hi Neela,

    You can write trigger on Contact for before delete event for this case.

    Please refer the below code. Change the sObject fields to your Own Custom Object fields

    trigger DontDeleteContact on Contact (before delete) {

        list<Id> ConId = new list<Id>();

        map<Id, List<sObject>> IDListMap = new map<Id, List<sObject>>();

        for(Contact C : Trigger.Old){

            ConId.add(C.Id);

        }

        for(sObject s : [select id, name, contact__c from sObject where contact__c IN :ConId order by contact__c]){

            for(Contact C : Trigger.Old){

                if(C.Id == s.contact__c){

                    c.addError('Contact have an existing related record. Hence it can not be deleted');

                }

            }

        }

    }

    Please let me know if it works.

    Please mark it as the solution if it helped you.

    Thanks,

    Jainam Contractor,

    Salesforce Consultant

    Varasi LLC

    www.varasi.com
0/9000