Skip to main content
Rajat Bhatt (Yash Technologies) 님이 #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개
  1. 2018년 12월 20일 오전 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