You need to sign in to do that
Don't have an account?
"unexpected token"
I am completely new to this, so I'm sure I'm missing something simple. I get the following error:
Error: Compile Error: unexpected token: 'Trigger.new' at line 2 column 138
when I try to save the following code:
trigger updateAccountName on Account (before Insert){
List<Lead> convertedLeads=[Select ID,ConvertedAccountId, Firstname__c, MiddleName__c, LastName__c FROM Lead WHERE ConvertedAccountId IN Trigger.new];
For (Account a: Trigger.new){
For (Lead l: convertedLeads){
if (l.ConvertedAccountId=a.ID){
a.Name=l.FirstName__c+l.MiddleName__c+l.LastName__c;
}
}
}
}
Thank you!!
|
The issue is with your IF statement using assignment operator instead of comparison :) Use double equals sign.
Try:
trigger updateAccountName on Account (before Insert){
List<Lead> convertedLeads=[Select ID,ConvertedAccountId, First_Name__c, Last_Name__c FROM Lead WHERE ConvertedAccountId IN :Trigger.newMap.keySet()];
For (Account a: Trigger.new){
For (Lead l: convertedLeads){
if (l.ConvertedAccountId==a.ID){
a.Name=l.First_Name__c+l.Last_Name__c;
}
}
}
}
All Answers
Try this :
List<Lead> convertedLeads=[Select ID,ConvertedAccountId, Firstname__c, MiddleName__c, LastName__c FROM Lead WHERE ConvertedAccountId IN :Trigger.newMap.keySet()];
Note the extra ' : ' and the use of the Map to get to the keySet (which is a Set if Id's in this case)
Awesome! That took care of that one--thank you very much! One new one:
Error: Compile Error: Field is not writeable: Lead.ConvertedAccountId at line 5 column 11
(and here's how the code looks now):
trigger updateAccountName on Account (before Insert){
List<Lead> convertedLeads=[Select ID,ConvertedAccountId, First_Name__c, Last_Name__c FROM Lead WHERE ConvertedAccountId IN :Trigger.newMap.keySet()];
For (Account a: Trigger.new){
For (Lead l: convertedLeads){
if (l.ConvertedAccountId=a.ID){
a.Name=l.First_Name__c+l.Last_Name__c;
}
}
}
}
Thank you again!
The issue is with your IF statement using assignment operator instead of comparison :) Use double equals sign.
Try:
trigger updateAccountName on Account (before Insert){
List<Lead> convertedLeads=[Select ID,ConvertedAccountId, First_Name__c, Last_Name__c FROM Lead WHERE ConvertedAccountId IN :Trigger.newMap.keySet()];
For (Account a: Trigger.new){
For (Lead l: convertedLeads){
if (l.ConvertedAccountId==a.ID){
a.Name=l.First_Name__c+l.Last_Name__c;
}
}
}
}