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

Populate Lead lookup field with a Lead text field value
I need a Lead trigger to populate a Lead lookup field (Financial_Institution_Name__c) with the value from a Lead text field (CU_IP__c). The lookup field is tied to a custom object called FI_Ref__c, where the key field is the Financial Institution Name. The CU_IP__c text field contains a FI Name value that will match up to the FI_Ref__c values in its Financial Institution Name field. The CU_IP__c field value is populated automatically when a new Lead record is populated via a Dataloader process. The import process provides a Source code from the Credit Union that supplied the Lead record. That Source code is used to determine the value that is placed in the CU_IP__c field. I need to copy the CU_IP__c field value and have it update into the Financial Institution Name field when the Financial Institution Name field is null.
trigger ForceSourceCrossRef on Lead (before insert, before update ) {
Set<String> sSources = new Set<String>();
for(Lead l : Trigger.new) {
if(l.Source__c != null) sSources.add(l.Source__c);
}
Map<String, CrossRef__c> mCrossRefs = new Map<String, CrossRef__c>();
for(CrossRef__c crInstance : [SELECT Id, Name FROM CrossRef__c WHERE Name IN :sSources]) {
mCrossRefs.put(crInstance.Name, crInstance);
}
for(Lead l : Trigger.new) {
if(l.Source__c != null) {
if(mCrossRefs.containsKey(l.Source__c)) {
l.Source_Cross_Reference__c = mCrossRefs.get(l.Source__c).Id;
}
}
}
}
Any ideas you may have will be helpful.