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

Getting Error message: Error: Compile Error: Invalid identifier ' '. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_'.
I am new to Apex Programming and I am trying to get through this error message.
Below is the code that I am working on
trigger DeDupe on Lead (before insert) {
for(Lead myLead : Trigger.new)
{
//Searching for matching contacts.Assigning them to the list by using bind variable. By using : with Apex Variable myLead
List<contact> matchingContacts = [SELECT Id FROM Contact
WHERE Email = :myLead.Email];
System.debug(matchingContacts.size() + 'contact(s) found.');
if(!matchingContact.isEmpty())
{
//Assign the lead to the data quslity queue
Group dataQualityGroup = [SELECT ID FROM Group
WHERE DeveloperName ='Data_Quality'
LIMIT 1];
myLead.OwnerID = dataQualityGroup.Id;
//Add the dupe contact IDS into the Lead description
String ContactMessage = 'Duplicate Contacts Found:\n';
for(Contact c = matchingContacts)
{
ContactMessage += c.FirstName + ' '
+ c.LastName + ' '
+ c.Account.Name + '('
+ c.Id + ;
}
myLead.Description = ContactMessage +'\n' + myLead.Description;
}
}
}
And I am getting following error messsage:
Error: Compile Error: Invalid identifier ' '. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_'.
Below is the code that I am working on
trigger DeDupe on Lead (before insert) {
for(Lead myLead : Trigger.new)
{
//Searching for matching contacts.Assigning them to the list by using bind variable. By using : with Apex Variable myLead
List<contact> matchingContacts = [SELECT Id FROM Contact
WHERE Email = :myLead.Email];
System.debug(matchingContacts.size() + 'contact(s) found.');
if(!matchingContact.isEmpty())
{
//Assign the lead to the data quslity queue
Group dataQualityGroup = [SELECT ID FROM Group
WHERE DeveloperName ='Data_Quality'
LIMIT 1];
myLead.OwnerID = dataQualityGroup.Id;
//Add the dupe contact IDS into the Lead description
String ContactMessage = 'Duplicate Contacts Found:\n';
for(Contact c = matchingContacts)
{
ContactMessage += c.FirstName + ' '
+ c.LastName + ' '
+ c.Account.Name + '('
+ c.Id + ;
}
myLead.Description = ContactMessage +'\n' + myLead.Description;
}
}
}
And I am getting following error messsage:
Error: Compile Error: Invalid identifier ' '. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_'.
I have updated your code. Please try below snippet: Hope this will help. Kindly let me know in case any query.
Please like the answer and mark it as best if this helps.
Thanks,
Aman
All Answers
I have updated your code. Please try below snippet: Hope this will help. Kindly let me know in case any query.
Please like the answer and mark it as best if this helps.
Thanks,
Aman
There was couple of errors in your code. You can take diffnow of both the codes using below site
https://www.diffnow.com/
Thanks,
Aman
trigger updateAccDescNew on Account (before Update)
{
Set<string> accIdSet = new Set<string>();
Map<Id,Opportunity> IdDescMap = new Map<Id,Opportunity>();
for (Account acc : trigger.new)
{
Account oldacc = trigger.oldMap.get(acc.Type);
if (acc.Type != oldacc.Type){
accIdSet.add(acc.Id);
}
}
if(accIdSet.size()>0)
{
for(Opportunity o : [Select id, Description from Opportunity where AccountId in : accIdSet order by CreatedDate DESC])
{
if(o.Description != null && o.Description != '')
{
IdDescMap.put(o.Id,o);
}
}
Map<Id, Account> idAccmap = new Map<Id, Account>();
for(Account acc : trigger.new)
{
if(!idAccmap.containsKey(acc.Id) && IdDescMap.containsKey(acc.Id))
{
idAccmap.put(acc.Id, acc);
acc.Description = IdDescMap.get(acc.Id).Description;
}
}
}
}