function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anand TripathiSBIAnand TripathiSBI 

how to change the owner of record from available list using aura component?

How to change owner of record(using List of active users in org) in aura component? I am trying to change the owner of the lead to available users in my org using aura component.
I want to display change owner button on my aura page and when i click thne list of users will poped up. And Now I can assign the lead to new owner. My code is given below.Please correct me.
*ChangeOwner.cmp*
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" controller="ChangeOwner" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>
*Controller*
 ({
 doInit : function(component, event, helper) {
        var leadId = component.get("v.recordId");
        var action = component.get("c.changeOwnerMethod");
        action.setParams({
            leadId : leadId
        });
        action.setCallback(this, function(response) {
            if(response.getState() === "SUCCESS") {
                console.log("Lead Owner Changed To Current login User");
             var rec = response.getReturnValue();
             console.log(rec.OwnerId);
            }
        });
        $A.enqueueAction(action);
        $A.get('e.force:refreshView').fire();
     $A.get("e.force:closeQuickAction").fire();
 }
})
//Apex Class//
public class ChangeOwner {
 @AuraEnabled
    public static Lead changeOwnerMethod(Id leadId) {
        if(leadId != null) {
            Lead l = [SELECT OwnerId FROM Lead WHERE Id = :leadId];
         l.OwnerId = UserInfo.getUserId();
            update l;
            return l;
        }
        return null;
    }

}