Convert Lead to Account and Auto Create an Opportunity Upon Booking Meeting

Note: this process uses triggers

Upon creating an event for a lead via Chili Piper Calendar Round Robin, you may use Salesforce triggers and a bit of APEX code to change the lead owner to the event’s assignee, convert the lead to a contact/account and open an opportunity, all automatically.

Here are the steps:

Assign and Convert the Lead

When a new event related to a lead is created set a trigger per below. The trigger will:

  • set the lead owner = assignee
  • call a class for conversion

Class for conversion.

Navigate to Salesforce Setup page -> App Setup -> Develop -> Apex Classes


Add the following code to a new 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();
Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
System.debug(‘LeadAssign Success’);

public AutoConvertLeads (Set<Id> LeadIds) {


Opportunity creation

This class above creates an opportunity with the account name as the default name of the opportunity & default stage.

Add Trigger

Add the trigger that will call the above class with a delay of 10 seconds:

Navigate to App Setup ->Customize -> Activities -> Event Triggers


Add the following code. You may change “Demo Small Business’” and “Demo Mid Market”  with the meeting types you already setup in Chili Piper.

trigger ChangeTheOwnerAndConvert on Event (after insert) {

   Set<Id> LeadIds = new Set<Id>();

   for (Event e:{

   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 Small Business’) ||

                                             e.Meeting_Type_CP__c.equals(‘Demo Mid Market’)){


                 Lead l = new Lead( Id = e.WhoId);

                 l.OwnerId = e.OwnerId;

                 update l;





   if(LeadIds.size() > 0){

       Datetime sysTime =;

       sysTime = sysTime.addSeconds(10);

       String chron_exp = ” + sysTime.second() + ‘ ‘ + sysTime.minute() + ‘ ‘ + sysTime.hour() + ‘ ‘ + + ‘ ‘ + sysTime.month() + ‘ ? ‘ + sysTime.year();

       System.schedule(‘ConvertLead’ + UserInfo.getUserId() +sysTime,chron_exp,new AutoConvertLeads(LeadIds));



Do not forget to activate the trigger at the end:


Still need help? Contact Us Contact Us