0

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

controller

    ({
 doInit : function(component, event, helper) {
        var opportunityId = component.get("v.recordId");
        var action = component.get("c.changeOwnerMethod");
        action.setParams({
           opportunityId : opportunityId
        });
        action.setCallback(this, function(response) {
            if(response.getState() === "SUCCESS") {
                console.log("opportunity Owner Changed To Current login User");
             var rec = response.getReturnValue();
             console.log(rec.OwnerId);
            }
        });
        $A.enqueueAction(action);
        $A.get('e.force:refreshView').fire();
 }
})

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"
                      recordId="{!v.recordId}"
                      fields="OpportunityNumber,OwnerId"
                      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>

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

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"
 lightningStylesheets="true">
<script>
        function showToast() {
            sforce.one.showToast({
                "title": "Success!",
                "message": "{!mySelectedSize} record updated successfully.",
                "type": "success"
            });
        }
    </script>

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

    </apex:pageBlock>  

    </apex:form>    
</apex:page>

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.