使用apex在salesforce中进行潜在客户转换

时间:2022-09-12 11:20:52

Hi i am trying to convert Lead into account and contact but this code convert only into contact and also don't deleted from lead please help. Thank in advance.

嗨,我正在尝试将Lead转换为帐户和联系,但此代码只转换为联系人,也不要从领导删除请帮助。预先感谢。

public class ConvertLead {
    public ConvertLead()
    {
        System.debug('convert lead called');
        Lead myLead = [SELECT Id FROM Lead WHERE FirstName = 'John'];
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(myLead.id);
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);   
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        System.debug('converted');

    }
}

1 个解决方案

#1


Your code is working fine, I've executed it anonymously from developer console

您的代码工作正常,我已经从开发人员控制台匿名执行了它

I have the following lead from default data which has been provided by SF for developer org:

我从SF为开发人员组织提供的默认数据中得到以下信息:

使用apex在salesforce中进行潜在客户转换

I've run your code from developer console for lead with name 'Bertha' the result was as following

我从开发人员控制台运行你的代码,名为'Bertha',其结果如下

使用apex在salesforce中进行潜在客户转换

So, please check the environment for things which might block conversion

因此,请检查环境中是否存在可能阻止转换的内容

#1


Your code is working fine, I've executed it anonymously from developer console

您的代码工作正常,我已经从开发人员控制台匿名执行了它

I have the following lead from default data which has been provided by SF for developer org:

我从SF为开发人员组织提供的默认数据中得到以下信息:

使用apex在salesforce中进行潜在客户转换

I've run your code from developer console for lead with name 'Bertha' the result was as following

我从开发人员控制台运行你的代码,名为'Bertha',其结果如下

使用apex在salesforce中进行潜在客户转换

So, please check the environment for things which might block conversion

因此,请检查环境中是否存在可能阻止转换的内容