Figure out how long and how much it takes to convert a lead to a deal

Business scenario:

We all know how much work goes into handling a lead, negotiating and converting them into deals. It doesn't stop there though. From the start of interacting with a lead to completing the deal and producing an invoice, the work included is too much. But that tedious and endless work becomes quantifiable contribution towards your organization.

Also having all the completed interactions documented and sorted out, you get an idea of how the mindset of customers work, or what are the current trends, etc. Don't look down on this little stat. A person who loves to talk in calls would be easier to convert a lead if the activity created is a call. Sending emails to such a customer might backfire.

So, how about having a custom button with a function that makes it possible to compile the total activities related to a lead. In addition, sort the activities based on the specific dates to get a clearer picture. For instance, displaying the number of days between the First activity created time (for the lead record) and the Lead converted date, updated in a custom number field.

 

Getting started with the function:

  1. Go to Setup > Customization > Modules and Fields > Select the required module > Links and Buttons > + New Button.
  2. Provide a name for the button. Add a description(optional).
  3. Choose View Page from the drop-down list.
  4. Select Writing Function from the subsequent drop-down.
  5. Provide a name for the function. Add a description(optional).
  6. Copy the code given below.
  7. Click Edit Arguments.
  8. Enter the name as recid and select the value as Lead Id.
  9. Enter the name as leadowner and select the value as Lead owner Id.
  10. Save the changes.
  11. Select the profiles who can see this button.
  12. Click Save.
 

The Code:

Sum of Total Activities(Open and Closed):


RelatedTasks = zoho.crm.getRelatedRecords("Tasks", "Leads", leadId.toLong(),1);
RelatedEvents = zoho.crm.getRelatedRecords("Events", "Leads", leadId.toLong(),1);
RelatedCalls = zoho.crm.getRelatedRecords("Calls", "Leads", leadId.toLong(),1);
totalcount = RelatedTasks.size() + RelatedEvents.size() + RelatedCalls.size();
mp = map();
mp.put("Activities_Count", totalcount);
update = zoho.crm.update("Leads", leadId.toLong(), mp);
info mp;
info update;
return "Success";
 

Sum of Total Activities(Open and Closed) for a particular time period(First Activity Created to Lead Converted Time):


converteddate = input.convertdate.toDate();
RelatedTasks = zoho.crm.getRelatedRecords("Tasks", "Leads", leadId.toLong(),1);
datelist = List();
for each task in RelatedTasks
{
taskcreateddate = task.get("Created_Time").toDate();
datelist.add(taskcreateddate);
}
RelatedEvents = zoho.crm.getRelatedRecords("Events", "Leads", leadId.toLong(),1);
for each event in RelatedEvents
{
eventcreateddate = event.get("Created_Time").toDate();
datelist.add(eventcreateddate);
}
RelatedCalls = zoho.crm._getRelatedRecords("Calls", "Leads", leadId.toLong(),1);
for each call in RelatedCalls
{
callcreateddate = call.get("Created_Time").toDate();
datelist.add(callcreateddate);
}
datevalue = datelist.sort().get(0);
daysdiff = days360(datevalue.toDate(),converteddate);
mp=map();
mp.put("Field_Name",daysdiff);
update = zoho.crm.update("Leads", leadId.toLong(), mp);
info mp;
info update;
return "Success";
 

Note:

  • You can also set this button in the List View page of the Module, to see the stats of all records simultaneously.
  • The above code works only for API V2.0 and not the previous version.
 

Found this useful? Try it out and let us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!

Return to Tips