Skip to main content
Hello All,

I'm extremely new to lightning components and trying to replace some of our custom javascript buttons with lightning compatible options.  One button takes ownership of a lead.  I found a post that does something similar for cases and tried to modify it for my purpose: https://learnownlightning.blogspot.com/2018/01/change-owner-update-record-using.html

It seems to be doing the record update based on apex code, but it launches a quickaction screen with a cancel button that doens't go away.  I've seen it posted that you can use 

$A.get("e.force:closeQuickAction").fire();

It is not working for me.  I'm not sure if I'm not puting that code in the right place but I'm hoping someone can help me figure out a way to click the quick action button, have the lead change ownership, and that's it.

Here is my code so far:

Component:

<aura:component implements="force:lightningQuickAction,force:hasRecordId" controller="LightningComponent_MoveToMarketing" 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:closeQuickAction").fire();

$A.get('e.force:refreshView').fire();

}

})

Apex Class:

public class LightningComponent_MoveToMarketing {

@AuraEnabled

public static Lead changeOwnerMethod(Id leadId) {

if(leadId != null) {

Lead l = [SELECT OwnerId FROM Lead WHERE Id = :leadId];

l.OwnerId = UserInfo.getUserId();

//update case Ownerid with loggedin userid.

update l;

return l;

}

return null;

}

}

Any ideas?

 
24 个回答
  1. 2019年10月10日 15:50

    Move 

    $A.get("e.force:closeQuickAction").fire();

    $A.get('e.force:refreshView').fire();

    inside the callback function. It should be good then.

    Your controller should be like this.

    ({

    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.get("e.force:closeQuickAction").fire();

    $A.get('e.force:refreshView').fire();

    }

    });

    $A.enqueueAction(action);

    }

    })

    Please mark it solved if this is working for you.

    Thanks.​​​​​​​
0/9000