0

I built a lightning component to make some changes to Lead Record and I added it as a quick action.

This is my helper.js:

changeOwnerAction : function(cmp,event) {

    var recordId = cmp.get("v.recordId");

    var action = cmp.get("c.changeOwnerForSelectedRecord");

    action.setParams({
        recordId : recordId
    });

    action.setCallback(this,function(res){
        var state = res.getState();
        if(state === "SUCCESS"){
            //do something
        }
    });

    $A.enqueueAction(action);
},

closeAction: function(cmp, event){ 
    var recordId = cmp.get("v.recordId");
    var sObectEvent = $A.get("e.force:navigateToSObject");
        sObectEvent .setParams({
        "recordId": recordId,
        "slideDevName": "detail"
    });
    sObectEvent.fire(); 
}

And the controller calls those functions one after another:

doInit : function(component, event, helper) {
    helper.changeOwnerAction(component,event);
    helper.closeAction(component,event);
}

The doInit is used in an handler:

<aura:handler name="init" value="{!this}" action="{!c.doInit}" />

At the end of the action the modal still shows for just a second but I've to wait few seconds to get the update available in the detail view as well as in the Lead state wizard.

has anyone else faced this issue?

  • Is your issue the fact that the modal is openend or the fact that the update is not immediate on the lead. Is this similar? salesforce.stackexchange.com/questions/170291/… – Eric Jul 3 '17 at 14:04
  • both are the issue, I've used the force:closeQuickAction for the modal, but i'm not understanding why when I reload the page in the view the update is not done yet even though doing a data export on the database the data are already updated! – Fabio Maturo Jul 3 '17 at 14:16
  • Is this in a community by chance? salesforce.stackexchange.com/questions/170062/… – Eric Jul 3 '17 at 14:17
  • Nope, my action is on a record detail in the lightning experience. – Fabio Maturo Jul 3 '17 at 14:34
0

I think its a performance issue. Both are running synchronously and waiting for each other too load. I suggest if you could put "this.closeAction" inside the SUCCESS clause of the changeOwnerAction so it would only close once server call has returned the successful results and remove it from the controllerJS. Improvement might be negligible but its an enhancement on the threading process.

  • I put the force:navigateToSObject into the callback when result is SUCCESS, but I'm still facing a bit of delay between UI record informations and Database informations. I made a query after the update and I got modified data even though in the UI old values are displayed. – Fabio Maturo Jul 4 '17 at 8:42
0

I understand that what you want is for this action to fire immediately upon clicking the button. However the way you've implemented it is not really considered good practice - the mere act of loading the component triggering a database update. https://developer.salesforce.com/page/Lightning_Security

Cross Site Request Forgery

In order to prevent CSRF attacks, do not invoke any server-side controller method that performs a DML operation automatically as the result of a page load. Specifically, do not invoke server-side DML controller method as onInit handlers, or afterRender handlers (if rendering is performed automatically on page load).

I have a similar use case in one client site where I wanted a Lightning Experience button to immediately execute Apex. What I did in the end was make a small Lightning component the size of a button, and used SLDS to style it as Lightning button. In App Builder I embedded that component as the topmost element of the sidebar in the Lightning layout. It's not in the same row as the other buttons but it still looks pretty natural. Clicking that component button instantly executes the desired Apex code with no modal, and the callback refreshes the Lightning record page.

  • Thanks Charles, I have been through the link and I got what u mean with "not really a good practice", btw, your button still responsive for salesforce1 app and table/mobile view? So what you mean is that It's not a good way to make an update by calling action through an handler because it's used only for load data that you are going to use in your component, right? – Fabio Maturo Jul 4 '17 at 7:29
  • So the idea with a cross site request forgery is - if you have a specific URL that changes database data when launched, then other websites can trick browsers logged into Salesforce into accessing the URL and changing your data. That's a security issue. – Charles T Jul 4 '17 at 13:26
  • As for mobile and tablet - I don't know. I think right now Lightning App Builder for record pages is limited to desktop layouts. If you can't embed it on mobile the course of action Salesforce would recommend is to make your Lightning component display a confirmation dialog, and clicking a button in that dialog launches the DML update. – Charles T Jul 4 '17 at 13:29
  • I reached my goal thanks to force:refreshView, in this case I get the field updated but in the Lead detail view I don't get the wizard update! – Fabio Maturo Jul 4 '17 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.