You need to sign in to do that
Don't have an account?
Tillu
Please currect below trigger issue ?
I have 2 objects policy and Interview. On Interview Record, i have policy as a lookup.
If interview fields contact name , Insured name matches with any policy record's contact name , Annuity name Then i have to pull the Policy record on to the Interview. I have written below code but failed. please any one update this ?
trigger Interview_PolicyUpdate on Interviews__c(before insert,before update) {
set<id> cset = new set<id>();
Map<Id,List<Policy__c>> policyMap = new Map<Id,List<Policy__c>>();
List<policy__c> poList = [select Id,name,Contact__c,Type__c,Annuitiant_Name__c from Policy__c where Contact__c in:cset ];
Map<Id,string> Intmap = new Map<id,string>();
for(Policy__c poli : PoList ){
if(policyMap.get(poli.Contact__c) !=null){
policyMap.put(poli.Contact__c,new list<policy__c>());
Intmap.put(poli.Id,poli.Annuitiant_Name__c);
}
}
for(Interviews__c Intrvews : Trigger.new){
for(Policy__c polic : PoList ){
if(policyMap.ContainsKey(Intrvews.Contact__c)&&policyMap.ContainsKey(Intrvews.Insured_Name__c)){ // Comparing both policy,Interview matches
Intrvews.Policy1__c = Polic.Id;
}
}
}
}
If interview fields contact name , Insured name matches with any policy record's contact name , Annuity name Then i have to pull the Policy record on to the Interview. I have written below code but failed. please any one update this ?
trigger Interview_PolicyUpdate on Interviews__c(before insert,before update) {
set<id> cset = new set<id>();
Map<Id,List<Policy__c>> policyMap = new Map<Id,List<Policy__c>>();
List<policy__c> poList = [select Id,name,Contact__c,Type__c,Annuitiant_Name__c from Policy__c where Contact__c in:cset ];
Map<Id,string> Intmap = new Map<id,string>();
for(Policy__c poli : PoList ){
if(policyMap.get(poli.Contact__c) !=null){
policyMap.put(poli.Contact__c,new list<policy__c>());
Intmap.put(poli.Id,poli.Annuitiant_Name__c);
}
}
for(Interviews__c Intrvews : Trigger.new){
for(Policy__c polic : PoList ){
if(policyMap.ContainsKey(Intrvews.Contact__c)&&policyMap.ContainsKey(Intrvews.Insured_Name__c)){ // Comparing both policy,Interview matches
Intrvews.Policy1__c = Polic.Id;
}
}
}
}
1) your poList will be empty because of empty cset variable
2) in the FOR loop this condition will be never met, because you never fill the map
I think the code below should do what you want - or at least act as a starting point.