You need to sign in to do that
Don't have an account?
Bhagya
Avoid deletion of opportunities if its child Consultant status is active. (create consultant object with fields-name,DOB,active,oppid(lookup),accountid(lookup))
Hi can someone help me with this trigger?
*Avoid deletion of opportunities if its child Consultant status is active.(create consultant object with fields-name,DOB,active,oppid(lookup),accountid(lookup)).
I've tried this, but I'm getting error in different way.
trigger OppConsultantTrigger on Opportunity (before delete) {
list<Consultant__c> cns = new list<Consultant__c>();
cns = [select id,name,status__c from Consultant__c where Opportunityid__c IN : Trigger.OldMap.keySet()];
for(opportunity o:trigger.old){
for(Consultant__c c : cns)
if(o.id== c.Opportunityid__c && c.status__c == 'Active')
{
o.adderror('you annot delete this opportunity');
}
}
}
*Avoid deletion of opportunities if its child Consultant status is active.(create consultant object with fields-name,DOB,active,oppid(lookup),accountid(lookup)).
I've tried this, but I'm getting error in different way.
trigger OppConsultantTrigger on Opportunity (before delete) {
list<Consultant__c> cns = new list<Consultant__c>();
cns = [select id,name,status__c from Consultant__c where Opportunityid__c IN : Trigger.OldMap.keySet()];
for(opportunity o:trigger.old){
for(Consultant__c c : cns)
if(o.id== c.Opportunityid__c && c.status__c == 'Active')
{
o.adderror('you annot delete this opportunity');
}
}
}
try with below code.
If this helps, Please mark it as best answer.
Thanks!!