Skip to main content
Rajat Bhatt (Yash Technologies) ha fatto una domanda in #Apex
Hi,

I am new to salesforce and i am facing an issue in writing a trigger.

The scenario is All the SALES user profile should be able to delete contact records except those records whose Status is Active.

Please help me in writing trigger.

Any help would be appreciated.

Thanks & Regards,

Ricky
4 risposte
  1. 20 dic 2018, 10:26
    Hi Ricky,

    Below code can help you.

    trigger deleteContact on Contact(before delete) {

    Id profileId = userinfo.getProfileId();

    String profileName = [Select Id from Profile where Id =: profileId].Name;

    //if you are using Status field as picklist then write con.Status__c == 'Active'.

    //if you are using Status field as checkbox then write con.Status.

    for (Contact con: trigger.old) {

    if (profileName == 'Sales' && con.Status__c) {

    if (Trigger.isBefore) {

    if (Trigger.isDelete) {

    con.adderror('You cannot delete the record');

    }

    }

    }

    }

    }

    Let me know if you have any confusion..

    Kindly mark this as solved if the reply was helpful.

    Thanks,

    Murali

     

     

0/9000