You need to sign in to do that
Don't have an account?
Pratik Mungalpara
Apex trigger on contact object to update field null when field have lookup relationship
I am new to coding and have a question.
Reuirement is: I have custom field (checkbox) named " inactive". another standard field on same object named "Report to". "Report To" field have lookup relationship to contact itself.
I want to remove any value in "report to" or i would say i want to make "report to" field null if "inacitve" field is checked.
Can you help me write trigger for it.
Reuirement is: I have custom field (checkbox) named " inactive". another standard field on same object named "Report to". "Report To" field have lookup relationship to contact itself.
I want to remove any value in "report to" or i would say i want to make "report to" field null if "inacitve" field is checked.
Can you help me write trigger for it.
Greetings!
Please refer the sample code given in this blog (https://developer.salesforce.com/forums/?id=9060G000000IBlvQAG).
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Use the below trigger for your requirement it may helpful for you
trigger TriggerForUpdateContactReport on Contact(before insert, before update) {
if( (trigger.isUpdate && trigger.isBefore) || (trigger.isInsert && trigger.isBefore)){
for(Contact con : trigger.new){
if(con.Inactive__c == true){
con.Report_To__c = '';
}
}
}
}
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com