You need to sign in to do that
Don't have an account?

unable to update field when match occures for below trigger ?
HI Folks,
I have 2 objects Policy , Interview. On interview record policy lookup is there. If interview fields Contact name , Insured name matches with any policy record's Contactname,Annuity name Then it should pull the policy on to the Interview record policy look up field.
I have writtened below code. But it was not works properly. There is no immediate update for the Policy look up field. Can any one correct below code ?
trigger Interview_PolicyUpdate on Interviews__c
(before insert,before update) {
set<id> cset = new set<id>();
set<string> Aset = new set<string>();
for(Interviews__c Intr : Trigger.new){
If(Intr.Contact__c != Null){
cset.add(Intr.Contact__c);
}
}
List<policy__c> po = [select Id,name,Contact__c,Type__c,Annuitiant_Name__c from
Policy__c where Contact__c in:cset ];
try{
for(Interviews__c Inr : Trigger.new){
for(Policy__c p : po){
//If(Inr.Annuitant_Name__c !=null){
if(p.Contact__c == Inr.Contact__c && Inr.Insured_Name__c == p.Annuitiant_Name__c){
Inr.Policy1__c = p.Id;
}
}
}
}
catch(Exception e){
System.Debug(e.getMessage());
}
}
I have 2 objects Policy , Interview. On interview record policy lookup is there. If interview fields Contact name , Insured name matches with any policy record's Contactname,Annuity name Then it should pull the policy on to the Interview record policy look up field.
I have writtened below code. But it was not works properly. There is no immediate update for the Policy look up field. Can any one correct below code ?
trigger Interview_PolicyUpdate on Interviews__c
(before insert,before update) {
set<id> cset = new set<id>();
set<string> Aset = new set<string>();
for(Interviews__c Intr : Trigger.new){
If(Intr.Contact__c != Null){
cset.add(Intr.Contact__c);
}
}
List<policy__c> po = [select Id,name,Contact__c,Type__c,Annuitiant_Name__c from
Policy__c where Contact__c in:cset ];
try{
for(Interviews__c Inr : Trigger.new){
for(Policy__c p : po){
//If(Inr.Annuitant_Name__c !=null){
if(p.Contact__c == Inr.Contact__c && Inr.Insured_Name__c == p.Annuitiant_Name__c){
Inr.Policy1__c = p.Id;
}
}
}
}
catch(Exception e){
System.Debug(e.getMessage());
}
}
Regards
Subhash