You need to sign in to do that
Don't have an account?
Trigger not updating lookup field
I have 2 objects (NRMA__c) (ts2__Application__c). I'm trying to update a look up field (Candidate__c) on the NRMA object with the Candidate field (ts2__Candidate_Contact__c) from the Application object.
I was able to accomplish other field updates like this through workflows, but for some reason, I was unable to update the Contract lookup field on the NRMA. I need this field to populate the Contact that is listed on the Application object.
Here is another run down of the fields and objects:
NRMA__c - object that includes a lookup to contacts (Candidate__c) - trying to update this field automatically
ts2__Application - object that includes a looup field to Contacts (ts2__Candidate_Contact__c).
When creating a new record on NRMA from Application, I want this to happen before update, before insert:
NRMA.Candiate c = Application.ts2__Candidate_Contact__c
Here is the trigger, but it's not working:
trigger CandidateTrigger on NRMA__C (before insert, before update) {
List<String> canList = new List<String>();
for (NRMA__c n:Trigger.new){
canList.add(n.Application__c);
}
List<ts2__Application__c> contactList = [SELECT Id, Name, ts2__Candidate_Contact__r.Id FROM ts2__Application__c WHERE Id in :canList];
Map<String, Id> nameToId = new Map<String, Id>();
for(ts2__Application__c c : contactList) {
nameToId.put(c.Name, c.Id);
}
for (NRMA__c n:Trigger.new){
n.Candidate__c = nameToId.get(n.Application__r.ts2__Candidate_Contact__r.Id);
}
}
Any ideas? Thanks!
try this
I hope it will work, Please let me know if any issues in it.
All Answers
try this
I hope it will work, Please let me know if any issues in it.
That worked great. Thank you.