function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bareera NoorBareera Noor 

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), '$', '_'. 
Best Answer chosen by Bareera Noor
Aman MalikAman Malik
Hi,
I have updated your code. Please try below snippet:
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(!matchingContacts.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;
                }
             }
}
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

Aman MalikAman Malik
Hi,
I have updated your code. Please try below snippet:
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(!matchingContacts.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;
                }
             }
}
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
 
This was selected as the best answer
Bareera NoorBareera Noor
Thankyou!! But would you explain me what was the error and why I am getting this error message.
Aman MalikAman Malik
Hi,
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
VarunKumarVarunKumar
Facing error message :- Error: Compile Error: Invalid identifier '    Set'. 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), '$', '_'. at line 3 column 1


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;
            }
        }
    }
}