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
tnstns 

Restrict non-administrators from deleting certain Contacts

Without using Record Types or Apex or Visual Force, does anyone have any ideas on how to restrict non-admin users from deleting Contacts that contain a value in a custom field that holds a Unique Id from an external system on the Contact record? It woudl be OK for users to delete a Contact that does not contain this unique id.

dmchengdmcheng

You can't do it without using either record types or an Apex trigger.

tnstns

Ok, thanks. If I use an Apex trigger (I have no expeience whatsoever with this), how would I set that up?

dmchengdmcheng
skodisanaskodisana

Hi,

 

Create another page layout without Delete button. Create Record Type and assign this page layout.

 

Using Workflow field update assign this page layout using record type and with the condition Unique Field is Not Equals to null.

 

Thanks,

Kodisana

Pradeep_NavatarPradeep_Navatar

Find below asample code for non admin users for deleting a specific contact :

 

                                                trigger dontdelacc on contact(before delete)

                                                {

                                                system.debug('############ '  + Trigger.old[0].id);

                                                try

                                                {

                                                                if(trigger.new.size()==1)

                                                                {

                                                                                if([select Id from Profile where name = 'Partner Staff'].id == UserInfo.getProfileId())

                                                                                {

                                                                                   // process your data

                                                                                   List<Contact> con = [select AccountId from Contact where AccountId=:Trigger.old[0].id];

                                                                                   if(con.size()>0)

                                                                                                {

                                                                                                                Trigger.old[0].id.addError('You cannot delete this ');

                                                                                                }

                                                                                }

                                                                }

                                                }

                                                catch(Exception e){}

                                                }

 

Hope this helps.