• Krishan Patel 1
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hey everyone! I'm still very new to Apex Code, but I've been trying to implement Chili Piper, and a portion of it allows you to automatically convert leads to contacts and opportunities: https://support.chilipiper.com/article/70-convert-lead-to-account-and-auto-create-an-opportunity-upon-booking-meeting

I've created a Sandbox environment, and built this Apex Class:
 
global class AutoConvertLeads implements Schedulable{

global Set<Id> LeadIds;

global void execute(SchedulableContext sc) {

LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
for(Id leadId : LeadIds){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(leadId);
Leadconvert.setConvertedStatus(Leads.MasterLabel);
Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
System.assert(Leadconverts.isSuccess());
System.debug('LeadAssign Success');
}
System.abortJob(sc.getTriggerId());
}

public AutoConvertLeads (Set<Id> LeadIds) {
this.LeadIds=LeadIds;
}

}

Then I created this event trigger:
 
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 (!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));
   }
}

The Event Trigger is checked as "Is Active", but when I create a lead and create an event on that least with the Meeting Type = Demo Request - Standard, nothing happens.

Does anyone have insight into this? Would love any help!

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!
Hey everyone! I'm still very new to Apex Code, but I've been trying to implement Chili Piper, and a portion of it allows you to automatically convert leads to contacts and opportunities: https://support.chilipiper.com/article/70-convert-lead-to-account-and-auto-create-an-opportunity-upon-booking-meeting

I've created a Sandbox environment, and built this Apex Class:
 
global class AutoConvertLeads implements Schedulable{

global Set<Id> LeadIds;

global void execute(SchedulableContext sc) {

LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
for(Id leadId : LeadIds){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(leadId);
Leadconvert.setConvertedStatus(Leads.MasterLabel);
Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
System.assert(Leadconverts.isSuccess());
System.debug('LeadAssign Success');
}
System.abortJob(sc.getTriggerId());
}

public AutoConvertLeads (Set<Id> LeadIds) {
this.LeadIds=LeadIds;
}

}

Then I created this event trigger:
 
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 (!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));
   }
}

The Event Trigger is checked as "Is Active", but when I create a lead and create an event on that least with the Meeting Type = Demo Request - Standard, nothing happens.

Does anyone have insight into this? Would love any help!

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!