You need to sign in to do that
Don't have an account?
Trigger Issue working on certain condition
Hi all,
I have written a trigger which will fetch the email field from contact and put it in email field in opportunity everytime after insert.
It doesn't work for myself. Its working only on workemail is selected and i am unable to guess where i am going wrong.
can anyone help me out of this.
trigger EmailRemainder on Opportunity (after insert)
{
Set<Id> ids=trigger.newmap.keySet();
List <OpportunityContactRole> ocr;
List<Contact> c;
List <Opportunity> op;
List <Opportunity> opList = new List<Opportunity>();
op=[select EmailRemainder__c from Opportunity where Id IN : ids];
ocr=[Select ContactId From OpportunityContactRole where OpportunityId IN : ids ];
if(ocr.isEmpty())
{
}
else
{
for(OpportunityContactRole r:ocr)
{
c=[select npe01__Preferred_Email__c,npe01__WorkEmail__c,npe01__AlternateEmail__c,npe01__HomeEmail__c from Contact where ID=: r.ContactId ];
}
for(Contact cc : c)
{
if(cc.npe01__Preferred_Email__c=='')
{
}
if(cc.npe01__Preferred_Email__c=='Work')
{
for(Opportunity ops:op)
{
for(Contact ci : c)
{
ops.EmailRemainder__c = ci.npe01__WorkEmail__c;
opList.add(ops);
}
}
update opList;
}
if(cc.npe01__AlternateEmail__c=='Alternate')
{
for(Opportunity ops:op)
{
for(Contact ci : c)
{
ops.EmailRemainder__c = ci.npe01__AlternateEmail__c;
opList.add(ops);
}
}
update opList;
}
if(cc.npe01__HomeEmail__c=='Personal')
{
for(Opportunity ops:op)
{
for(Contact ci : c)
{
ops.EmailRemainder__c =ci.npe01__HomeEmail__c;
opList.add(ops);
}
}
update opList;
}
}
}
}
Thanks in advance
Can you check which if condition is being executed when you run it for yourself.Put the debug ements and check Debug logs to verify that.
Thanks vinit.
I got the place where i was wrong i didn't used preferrred email in exact places. its working fine.