+ Start a Discussion
Vandana RattanVandana Rattan 

Custom Lead Convert issue

 Ihave created workflow rules to assign leads to a Particular Owner's queue on lead creation. So, after the lead is created it will be assigned to the owner's queue. Now I have written a custom Lead Convert VisualForce page. But when I click on Convert button, it gives error:-

 ConvertLead failed. First exception on row 0; 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.: []
Error is in expression '{!ConvertLead}' in component <apex:commandButton> in page customleadconvert

This error comes as the lead is still assigned to the queue and conversion requires the lead to be assigned to owner. How can I automate the assignment back to User A if the lead is assigned to A's queue when my custom VF page loads? My VF Page is given below:
<apex:page standardController="Lead" extensions="LeadConvertController">
    <apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" />
     <apex:sectionHeader title="Convert {!$ObjectType.Lead.label}" subtitle="{!Lead.name}"/>
    <apex:form >
        <apex:pageBlock mode="edit" >
       
        <apex:pageblockbuttons >
                <apex:commandbutton value="Convert" action="{!ConvertLead}"/>
                <apex:commandbutton value="Cancel" action="{!Cancel}"/>
        </apex:pageblockbuttons>
        
        <apex:pageblocksection id="LeadConvertPBS" title="Convert Lead">
         <apex:pageBlockSectionItem >
            <apex:outputLabel value=" Record Owner" for="Record Owner"/>
            <apex:inputField value="{!Lead.OwnerID}" id="recOwner"/>
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="Account Name">Account Name</apex:outputLabel>
             <apex:inputField required="true" id="company" value="{!Lead.Company}" />
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
           <apex:OutputLabel for="Send Email to the Owner">Send Email to the Owner</apex:OutputLabel>
           <apex:inputCheckbox onclick="{!Lead.Ownerid}"/>
           </apex:pageBlockSectionItem> 
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="Oppt Name">Opportunity Name:</apex:outputLabel>
             <apex:inputField required="true" id="Owner" value="{!Lead.Company}" />
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
                      <apex:outputLabel for="ConStatus">Converted Status:</apex:outputLabel>
             <apex:inputField id="ConStatus" value="{!Lead.Status}" />
          </apex:pageBlockSectionItem>
          <apex:pageblockSectionItem >
              <apex:outputLabel for="no oppty">Do not create new opportunity upon conversion</apex:outputLabel>
               <apex:inputCheckbox id="noOppty"/>
               
          </apex:pageblockSectionItem>
        </apex:pageblocksection> 
  <apex:pageblocksection id="BookingPBS" title="Booking Details">
         <apex:pageblockSectionItem >
                <apex:outputLabel for="BookingStart">Booking Start Date/Time</apex:outputLabel>
         <apex:inputField id="BookingStart" value="{!lead.Booking_Start_Date_Time__c}"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel for="BookingEnd">Booking End Date/Time</apex:outputLabel>
         <apex:inputField id="BookingEnd" value="{!lead.Booking_End_Date_Time__c}"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel for="BookingOwner">Booking Owner</apex:outputLabel>
         <apex:inputField id="BookingOwner" value="{!lead.Booking_Owner__c}"/>
            </apex:pageblockSectionItem>
            </apex:pageblocksection>
            <apex:pageblocksection id="ServicePBS" title="Service Type">
            <apex:pageblockSectionItem >
                <apex:outputLabel for="ServiceFree30Min">Free 30 Minute Assessment</apex:outputLabel>
                <apex:inputCheckbox id="ServiceFree30Min" value="{!lead.Free_30_Minute_Assessment__c}"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel for="ServicePutterFitting">Putter Fitting</apex:outputLabel>
                <apex:inputCheckbox id="ServicePutterFitting" value="{!lead.Putter_Fitting__c}"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel for="ServiceWedgeFitting">Wedge Fitting</apex:outputLabel>
                <apex:inputCheckbox id="ServiceWedgeFitting" value="{!lead.Wedge_Fitting__c}"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel for="ServiceIronFitting">Iron Fitting</apex:outputLabel>
                <apex:inputCheckbox id="ServiceIronFitting" value="{!lead.Iron_Fitting__c}"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel for="ServiceDriverFitting">Driver Fitting</apex:outputLabel>
                <apex:inputCheckbox id="ServiceDriverFitting" value="{!lead.Driver_Fitting__c}"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel for="ServiceWoodsHybridFitting">Woods + Hybrid Fitting</apex:outputLabel>
                <apex:inputCheckbox id="ServiceWoodsHybridFitting" value="{!lead.Woods_Hybrid_Fitting__c}"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel for="ServiceTrackmanGolfLesson">Trackman Golf Lesson</apex:outputLabel>
                <apex:inputCheckbox id="ServiceTrackmanGolfLesson" value="{!lead.Trackman_Golf_Lesson__c}"/>
            </apex:pageblockSectionItem>
        </apex:pageblocksection>
        </apex:pageBlock>
        
    </apex:form> 

</apex:page>

 
Best Answer chosen by Vandana Rattan
Vandana RattanVandana Rattan
Resolved the issue by following the steps mentioned below:-

Got the queueid to which the record is associated.
Queried the GroupMember object to get the UserOrGroupId associate with the queueid.
Set the ownerid to the extracted UserOrGroupId

All Answers

Vandana RattanVandana Rattan
Resolved the issue by following the steps mentioned below:-

Got the queueid to which the record is associated.
Queried the GroupMember object to get the UserOrGroupId associate with the queueid.
Set the ownerid to the extracted UserOrGroupId
This was selected as the best answer
Dominic Sebastian 7Dominic Sebastian 7
Could you please also mention the LeadConvertController class here as well ??