How can I solve this intermittent issue?

I have a user that is having an issue with a spinner staying on the page. I have a callback with if else seen below. The issue is intermittent. I have yet to be able to reproduce the issue.

Here is my JS Controller

var spas = $A.get("e.c:spinner");
    var opps = cmp.get("v.quotes");
    var action = cmp.get("c.updateopps");
    action.setParams({"opps": cmp.get("v.quotes")
    action.setCallback(this, function(data) {
        var rslt = data.getState();
        if (rslt === "SUCCESS"){
            //toggle spinner
            var resultsToast = $A.get("e.force:showToast");
                "title": "Resubission Request Submitted",
                "message": "Request was sent to bid desk",
                "type" : "success",
                "key" : "approval"
            alert('There Were some Errors. Please Contact Admin');


and for my apex class

public static List<sObject> updateopps(List<SObject> opps)
    update opps;
    return opps;

Since this is a list which often has only one record being updated,I am curious if this is part of the issue or if it is something completely different. Or should I just use a try catch in the apex class? My concert with try catch is that the error could be on a record they are not updating and do not want to cause confusion by telling them unneeded information.

Any help would be awesome.

  • If there was an error, you definitely want to report that. If you have concerns about cascading errors, consider just giving a generic message instead. A try-catch means the record won't be updated at all, and the last thing you want to do is tell the user their work was saved when it actually was not.
    – sfdcfox
    Mar 2 '18 at 22:03
  • @sfdcfox every time this has happend, the record did save. Mar 3 '18 at 0:09

The problem is scope - spa is not reachable at the callback, especially if it was triggered outside of component itself (for example - from a library loaded from static resource).

Firstly, you should wrap your callback: action.setCallback(this, $A.getCallback(function(data) {

Secondly, toggle your spinner by getting the event directly: $A.get("e.c:spinner").fire()

Then, fire your spinner event immediately in the callback, rather than in somewhere deeper in code - you are at greater risk of encountering exceptions and leaving user blocked from recovering from them.

Finally, in doing last step you don't need to write the same redundant code in your else block, just report the error to user.

You should definitely do try/catch in your apex and report those exceptions using throw new AuraHandledException(dmlException.getMessage()). Also instead of returning records directly, requery the records so user sees modifications that has happened via triggers, process builder, workflows, etc.

  • thanks, this is one of the best responses I have gotten on any question. I do have a question. If spa is not reachable, why does it work most of the time? It seems like the statement firing the event in the callback instead of with if /else makes a ton of sense . Mar 5 '18 at 18:50

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.