0

Converting lead to contact, when Email field of lead and contact is same.I queried lead and contact. Looped the Contact and lead checked the emails field, if it is same insert into a list. Then loop through that list and tried to convert lead into contact whose Email is same. But it is throuing an error at run time.

"System.DmlException: ConvertLead failed. First exception on row 1; first error: REQUIRED_FIELD_MISSING, Converted objects can only be owned by users. If the lead is not owned by a user, you must specify a user for the Owner field.: [OwnerId]"

.

Queried code is:-

leadQuery_Result =[Select id, Email, Status, ownerID from Lead where Email != null and Status IN ('L3. Closed - Qualified New' , 'L3. Closed - Onboarding' , 'L3a. Closed - Existing') and 
        isConverted = False Limit 20 ];

Conversion code is:

List<Database.LeadConvert> lc_lst = new List<Database.LeadConvert>();  
        //Looping through lead List and adding Lead ID. 
            system.debug(' lead to convert :'+leadList_To_Convert); 
            System.Debug('Converting list Lead : ' + lc_lst);  
            for(Lead ltc : leadList_To_Convert){  
                System.Debug('Converted Lead: ' + ltc); 
                 if(ltc.ID != null){ 
                    Database.LeadConvert lc = new Database.LeadConvert(); 
                    lc.setLeadId(ltc.ID);
                    lc.setDoNotCreateOpportunity(True);  
                    //lc.setOwnerId(ownerID);
                    lc.setConvertedStatus('L3a. Closed - Existing');  
                    lc_lst.add(lc); 
                    System.Debug('Converted Lead after conversion : ' + ltc); 
                } 

             }  
             System.Debug('Converting list Lead : ' + lc_lst);  
             // Lead Converting.
                Database.LeadConvertResult[] lcr = Database.convertLead(lc_lst); 
                System.Debug('Converted Lead : ' + lcr); 

1 Answer 1

1

It seems like it has nothing to do with your code. The error generated is really explicit : lead owner is probably a queue, and you can only convert lead owned by a queue. You have to change it, and set an user.

1
  • If, i am system admin but my lead owner is another, at that time can i convert lead to contact?
    – SFDC 44
    Apr 15, 2015 at 9:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .