Skip to main content
We have a number of contact records in our database that meet certain criteria (user ID not equal to blank). Lets call this type of contact a Master Contact. I need to ensure that these Master contact records cannot be deleted and that the contact ID for this record remains the same.

 

I also want to ensure that when this Master record is merged with another record that the contact ID of the master contact record is always used and that it is not possible to merge two master contact records. 

 

Has anyone ever tried to do this and what method did they use?

 

Hanks in advance!
답변 14개
  1. 2017년 4월 21일 오전 11:40
    Hi Lousie,

     

    There are two things in your question:

     

    1. To prevent deletion of master type of contact records. 

     

    For this problem, I would suggest a very simple apex trigger to be written on contact object on before delete event. Please try creating a trigger with the below code, just a small change at line number 3, replace userId with your field API name. 

    trigger preventDeletion on contact (before delete){

    for(contact con : trigger.old){

    if(con.userId != null){

    con.addError('You can not delete these kind of contact records');

    }

    }

     

    2. To allow merging only if your master type of contact is selected as Master record in merging. 

     

    This will be taken care automatically I think, because you have already prevented deletion of master type of contacts. Because what happens during merging is, merge process tries to delete the slave records during merging, and if your master type of contact will be chosen as slave, SF will try to delete it, and your apex trigger won't allow that. 

     

    Please try, hope this helps !!

     

    Thanks

     

    Nitish
0/9000