1

I have a problem, I need to convert the direct lead, when I click on the convert button it opens a window to fill in some data like, opportunity name, task, and reminder.

Lead Convert Default

I created these fields in the lead screen so that it is populated before and when I click on the button, convert the conversion to be direct without the default screen, I will post some images of how I want

Custom Fields in Lead Screen

I currently have a button to convert with the following code

{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")}

var id = '{!Lead.Id}';

var link = sforce.apex.execute('BotaoJavaScript', 'criarLead', {leadId:id}); 

window.location.href = link;

this button refers to this apex class

Global without sharing class BotaoJavaScript {

    webservice static string criarLead(Id leadId){
        System.debug('Id Lead: ' + leadId);
        String link = '/{IdAcc}';
        LeadDAO leadDAO = new LeadDAO();
        Lead lead = leadDAO.getLeadById(leadId);


        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(leadId);

        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        lc.setDoNotCreateOpportunity(String.isEmpty(lead.Name));

        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());

        }
        System.debug(JSON.serialize(lc));
        link = link.replace('{IdAcc}', lc.getAccountId());

        System.debug('Link: ' + link );
        return link;
    }
}

the lead is converted but all fields get null, I made a debug serialize and I had this return from the Developer Console

16:11:43:652 USER_DEBUG [46]|DEBUG|{"accountId":null,"accountRecord":null,"bypassAccountDedupeCheck":null,"bypassContactDedupeCheck":null,"contactId":null,"contactRecord":null,"convertedStatus":"Qualificado","doNotCreateOpportunity":true,"leadId":"00Q1F000002dXM1","opportunityId":null,"opportunityName":null,"opportunityRecord":null,"overwriteLeadSource":false,"ownerId":null,"sendNotificationEmail":false}

Can someone help me with how to make this change?

Your Answer

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

Browse other questions tagged or ask your own question.