Convert a Lead automatically when a specific field matches criteria, creating an Account, Contact, and Deal simultaneously.
Sales reps hate admin work. When a lead is finally qualified, standard Zoho CRM behavior requires the rep to click "Convert", select account creation options, fill in deal details, and save. This multi-step process often leads to data entry errors or reps skipping deal creation entirely.
We need a way to automate this entire conversion process the moment a lead status changes to "Qualified".
Zoho provides a powerful zoho.crm.convertLead() integration task. This script automatically handles the conversion, taking the Lead's data, mapping it to a Contact and Account, and generating a new Deal in one seamless background action.
mapping JSON object. The keys overwrite, notify_lead_owner, and notify_new_entity_owner are crucial boolean flags that mimic the checkboxes you see in the manual conversion UI.Deals map inside the main mapping, we instruct Zoho to generate an Opportunity/Deal. Notice we programmatically set the Closing_Date to 30 days from today using today.addDay(30).Attach this script to a Workflow Rule on the Leads module. Set the trigger to "Field Update" on the Lead Status field, looking for the value "Qualified".
// Convert Lead mapping
mapping = Map();
mapping.put("overwrite",true);
mapping.put("notify_lead_owner",true);
mapping.put("notify_new_entity_owner",true);
// Deal Details
dealMap = Map();
dealMap.put("Deal_Name", leadName + " Deal");
dealMap.put("Closing_Date", today.addDay(30));
dealMap.put("Stage", "Qualification");
dealMap.put("Amount", 5000);
mapping.put("Deals", dealMap);
// Execute Conversion
response = zoho.crm.convertLead(leadId, mapping);
info response;