You need to sign in to do that
Don't have an account?
Sourav P
Autopopulate a custom object field into the Lead object using a Trigger
Hi, I just wrote the below trigger but its showing the error, Can anyone plz help me out where it went wrong. thanks
Custom object : True_Promo__c, Custom field name : TrueYou_Privilege1_Code__c
Standaard Object : Lead, Custom Field Name : TrueYou_Privilege_Code__c
I want the "TrueYou_Privilege1_Code__c" input from the custo object should auto populate into teh lead object field.
ERROR showing : Compile Error : Invalid field lead for sObject True_Promos__c at line 18 column 13
trigger SetLeadOnTruePromo on True_Promos__c (before update, before insert) {
Set<string> TruePrivileges = new Set<string>();
for (True_Promos__c checkTPrivilege : Trigger.new) {
TruePrivileges.add(checkTPrivilege.TrueYou_Privilege1_Code__c);
}
List<Lead> LeadList = [SELECT id, TrueYou_Privilege_Code__c FROM Lead WHERE TrueYou_Privilege_Code__c IN :TruePrivileges];
Map<string, Lead> PrivilegeCodeToLeadMap = new Map<string, Lead>();
for (Lead c : LeadList) {
PrivilegeCodeToLeadMap.put(c.TrueYou_Privilege_Code__c, c);
}
for (True_Promos__c p : Trigger.new) {
if (p.TrueYou_Privilege1_Code__c != null) {
p.Lead = PrivilegeCodeToLeadMap.get(p.TrueYou_Privilege_Code__c).id;
}
else {
p.Lead = null;
}
}
}
Custom object : True_Promo__c, Custom field name : TrueYou_Privilege1_Code__c
Standaard Object : Lead, Custom Field Name : TrueYou_Privilege_Code__c
I want the "TrueYou_Privilege1_Code__c" input from the custo object should auto populate into teh lead object field.
ERROR showing : Compile Error : Invalid field lead for sObject True_Promos__c at line 18 column 13
trigger SetLeadOnTruePromo on True_Promos__c (before update, before insert) {
Set<string> TruePrivileges = new Set<string>();
for (True_Promos__c checkTPrivilege : Trigger.new) {
TruePrivileges.add(checkTPrivilege.TrueYou_Privilege1_Code__c);
}
List<Lead> LeadList = [SELECT id, TrueYou_Privilege_Code__c FROM Lead WHERE TrueYou_Privilege_Code__c IN :TruePrivileges];
Map<string, Lead> PrivilegeCodeToLeadMap = new Map<string, Lead>();
for (Lead c : LeadList) {
PrivilegeCodeToLeadMap.put(c.TrueYou_Privilege_Code__c, c);
}
for (True_Promos__c p : Trigger.new) {
if (p.TrueYou_Privilege1_Code__c != null) {
p.Lead = PrivilegeCodeToLeadMap.get(p.TrueYou_Privilege_Code__c).id;
}
else {
p.Lead = null;
}
}
}
Thanks for pointing out an issue. I ran your code, but till i am getting the same error alert " Error: Compile Error: Invalid field Lead for SObject True_Promos__c at line 14 column 13.
I cant understand why its showing invalid Lead field. Do we have to do somthing to the standard object Lead ? Thanks
Can you share your requirement?