I want to add 'Change Owner' button on the opportunity list view page by using lightning component. I am using below code but can not see change owner button on my opportunity list page


 doInit : function(component, event, helper) {
        var opportunityId = component.get("v.recordId");
        var action = component.get("c.changeOwnerMethod");
           opportunityId : opportunityId
        action.setCallback(this, function(response) {
            if(response.getState() === "SUCCESS") {
                console.log("opportunity Owner Changed To Current login User");
             var rec = response.getReturnValue();

lightning component

    <aura:component implements="force:hasRecordId,flexipage:availableForRecordHome,force:lightningQuickAction">
  <aura:attribute name="complete" type="Boolean" default="false" />
    <aura:attribute name="opportunityRecord" type="Object"/>
    <force:recordData mode="EDIT" aura:id="recordLoader"
                      targetFields="{!v.opportunityRecord}" />
    <aura:if isTrue="{!v.opportunity.OwnerId != $SObjectType.CurrentUser.Id}">
    <aura:if isTrue="{!not(v.complete)}">
        <lightning:input type="toggle" messageToggleActive="" messageToggleInactive="" label="Are you sure to take the ownership on this Opportnity record?" name="input1" onchange="{!c.handleClick}"/>

    <aura:if isTrue="{!v.complete}">
        Opportunity is assigned to new Owner. 
    <aura:if isTrue="{!v.opportunityRecord.OwnerId == $SObjectType.CurrentUser.Id}">
        opportunity is already assigned to owner.

I can see VF page button on my oppty list view page, but I want this feature to implement via lightning component

VF page  code'

    <apex:page standardController="Opportunity" recordSetVar="opportunities" extensions="Workaround" showHeader="false"
        function showToast() {
                "title": "Success!",
                "message": "{!mySelectedSize} record updated successfully.",
                "type": "success"

    <apex:form id="muform">
        <apex:pageMessage summary="Selected Collection Size: {!mySelectedSize}" 
                          id="mupms" />
  <apex:pageBlock >
      <apex:pageBlockSection >
      <apex:inputField value="{!Opportunity.OwnerId}" />
    <apex:pageBlockTable value="{!selected}" var="opp">
        <apex:column value="{!opp.Name}"/>    
      <apex:commandButton action="{!Save}" value="Save" onclick="showToast();" />
      <apex:commandButton value="Cancel" action="{!cancel}" />



Apex Controller :

public class Workaround {
 ApexPages.StandardSetController setCon;

    public selectedSizeWorkaround(ApexPages.StandardSetController controller) {
        setCon = controller;

    public integer getMySelectedSize() {
                return setCon.getSelected().size();

    public integer getMyRecordsSize() {
        return setCon.getRecords().size();
  • Please don't post under multiple accounts. Use the Contact link at the bottom of every page to ask Stack Exchange to merge your duplicates. – David Reed Aug 12 '19 at 11:07

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.