You need to sign in to do that
Don't have an account?
Bhagya
Avoid deletion of contact related to account.
Can someone help me with this trigger?
Avoid deletion of related contact while deleting account which has rating as 'warm' and No_of_Employees__c is not empty(add error message).
I've tried this, but not working and not showing error message.
trigger AvoidContactDel on Account (before delete) {
list<account> acc = new list<account>();
list<contact> con = new list<contact>();
set<id> ids = new set<id>();
for(account a : trigger.old){
ids.add(a.id);
}
con = [select id,lastname from contact where accountid IN : ids ];
//acc = [select id,name,stage,No_of_Employees__c from account where id in : ids];
for(account a : trigger.old){
for(contact c : con){
if(a.id == c.accountid && a.rating == 'Warm' && a.No_of_Employees__c != null){
a.adderror('you are not allow to delete this contact for some reasons');
}
}
}
}
Avoid deletion of related contact while deleting account which has rating as 'warm' and No_of_Employees__c is not empty(add error message).
I've tried this, but not working and not showing error message.
trigger AvoidContactDel on Account (before delete) {
list<account> acc = new list<account>();
list<contact> con = new list<contact>();
set<id> ids = new set<id>();
for(account a : trigger.old){
ids.add(a.id);
}
con = [select id,lastname from contact where accountid IN : ids ];
//acc = [select id,name,stage,No_of_Employees__c from account where id in : ids];
for(account a : trigger.old){
for(contact c : con){
if(a.id == c.accountid && a.rating == 'Warm' && a.No_of_Employees__c != null){
a.adderror('you are not allow to delete this contact for some reasons');
}
}
}
}
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Kindly check these 2 links where similar task has been discussed :-
1. https://salesforce.stackexchange.com/questions/111098/account-that-has-related-contacts-should-not-be-deleted
2. https://developer.salesforce.com/forums/?id=9060G0000005QR4QAM
Kindly mark it as the best answer if it works for you.
Thanks & Regards,
Priya Ranjan