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
Krishan Patel 1Krishan Patel 1 

Compiler Error due to Apex Identifiers?

Hey everyone! I've been trying to implement this code snippet, but keep running into errors around Apex Identifiers:

 

Error: Compile Error: Invalid identifier '’00Q’'. 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 6 column 36
 

Error: Compile Error: Invalid identifier '‘Demo'. 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 7 column 45
 

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), '$', '_'. at line 17 column 27


Here is the code:

trigger ChangeTheOwnerAndConvert on Event (after insert) {
   Set<Id> LeadIds = new Set<Id>();
   for (Event e: Trigger.new){
   if (e.WhoId != null){
        String eventNameId = e.WhoId;
        if (eventNameId.startsWith(’00Q’) && !String.isBlank(e.Meeting_Type_CP__c)){
            if (e.Meeting_Type_CP__c.equals(‘Demo Request - Standard’)){
                 LeadIds.add(e.WhoId);
                 Lead l = new Lead( Id = e.WhoId);
                 l.OwnerId = e.OwnerId;
                 update l;
                }
          }     
     }
   }
   if(LeadIds.size() > 0){
       Datetime sysTime = System.now();
       sysTime = sysTime.addSeconds(10);
       String chron_exp = ” + sysTime.second() + ‘ ‘ + sysTime.minute() + ‘ ‘ + sysTime.hour() + ‘ ‘ + sysTime.day() + ‘ ‘ + sysTime.month() + ‘ ? ‘ + sysTime.year();
       System.schedule(‘ConvertLead’ + UserInfo.getUserId() +sysTime,chron_exp,new AutoConvertLeads(LeadIds));
   }
}

Does anyone know how to get around this? I'm very new to all of this still and took the code from this article: https://support.chilipiper.com/article/70-convert-lead-to-account-and-auto-create-an-opportunity-upon-booking-meeting


Thank you so much to anyone that can even attempt to help!
Best Answer chosen by Krishan Patel 1
Raj VakatiRaj Vakati
Use this .. Apex will accept  only single quote for the string 

and use this code
 
trigger ChangeTheOwnerAndConvert on Event (after insert) {
   Set<Id> LeadIds = new Set<Id>();
   for (Event e: Trigger.new){
   if (e.WhoId != null){
        String eventNameId = e.WhoId;
        if (eventNameId.startsWith('00Q') && !String.isBlank(e.Meeting_Type_CP__c)){
            if (e.Meeting_Type_CP__c.equals('Demo Request - Standard')){
                 LeadIds.add(e.WhoId);
                 Lead l = new Lead( Id = e.WhoId);
                 l.OwnerId = e.OwnerId;
                 update l;
                }
          }     
     }
   }
   if(LeadIds.size() > 0){
       Datetime sysTime = System.now();
       sysTime = sysTime.addSeconds(10);
       String chron_exp = ' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
       System.schedule('ConvertLead' + UserInfo.getUserId() +sysTime,chron_exp,new AutoConvertLeads(LeadIds));
   }
}

 

All Answers

Andrew GAndrew G
Hi
You seem to have funky quotes around your string ’00Q’  .  If you look at the quotes before ’00Q’, it seems backwards, yet the quotes around ‘Demo Request - Standard’ seem to show correctly - as opening first, then closing.

Try retyping the entire string, including the single quotes.  Depending on the editor you are using, it should put the single quote in correctly. 

Regards
Andrew
Raj VakatiRaj Vakati
Use this .. Apex will accept  only single quote for the string 

and use this code
 
trigger ChangeTheOwnerAndConvert on Event (after insert) {
   Set<Id> LeadIds = new Set<Id>();
   for (Event e: Trigger.new){
   if (e.WhoId != null){
        String eventNameId = e.WhoId;
        if (eventNameId.startsWith('00Q') && !String.isBlank(e.Meeting_Type_CP__c)){
            if (e.Meeting_Type_CP__c.equals('Demo Request - Standard')){
                 LeadIds.add(e.WhoId);
                 Lead l = new Lead( Id = e.WhoId);
                 l.OwnerId = e.OwnerId;
                 update l;
                }
          }     
     }
   }
   if(LeadIds.size() > 0){
       Datetime sysTime = System.now();
       sysTime = sysTime.addSeconds(10);
       String chron_exp = ' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
       System.schedule('ConvertLead' + UserInfo.getUserId() +sysTime,chron_exp,new AutoConvertLeads(LeadIds));
   }
}

 
This was selected as the best answer
Krishan Patel 1Krishan Patel 1
Thank you both so much! I'm very new to this, so I copy and pasted the code. I now see how it can be easy to mistake ` with '.

Everything works now :)