2

Within our Web-to-Lead forms we use a hidden form field to identify the forms location. Is it possible to automatically convert certain leads (if the hidden form field matches our requirements) directly into a new account?

0

One option would be to use a trigger on lead that automatically converts the lead based on the field value.

NOTE: This trigger was written to show you the general idea. I haven't tested it in practice.

trigger convertLead on Lead (after insert) {

    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];

    List<Database.LeadConvert> conversions = new List<Database.LeadConvert>();

    for(Lead l : Trigger.new) {
        // This is where you can test your hidden field requirements.
        if(l.CustomField__c == 'convertCondition') {
            Database.LeadConvert lc = new database.LeadConvert();
            lc.setLeadId(l.Id);
            lc.setDoNotCreateOpportunity(True);
            lc.setConvertedStatus(convertStatus.MasterLabel);

            // Use List to bulkify conversion process rather than doing one at a time
            conversions.add(lc);
            //Database.LeadConvertResult lcr = Database.convertLead(lc);
            //System.assert(lcr.isSuccess());
        }
    }

    if(conversions.size() > 0) {
        List<Database.LeadConvertResult> lcrs = Database.convertLead(lc);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.