function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vishal-negandhivishal-negandhi 

Execute Aura controller method without waiting for Apex response

Hello Experts, 

I've been stuck in a problem and need some inputs.
We have a contact form and on submit of it, we are creating a Case record in the backend.

The problem is, the logic is pretty complex and the form submission at times takes more than 10 seconds. We have optimized our code as much as we could, but we have a lot of background processes on Cases such as PB's, WF's, before and after triggers, etc and all of that combined is making the response too slow.

What we have on the aura component
 

submitCase: function(component, fileNames, fileTypes, files, t0){
    llet action = component.get('c.submit');
    action.setParams({
       // set some params
    });
    
    action.setCallback(this,function(response){
        let status = response.getState();
     
        if(status === 'SUCCESS'){
            // some console statements
        }
        else if(status === 'ERROR'){
           // some console statements
        }
    }); 
    
    $A.enqueueAction(action); 
    var cmpEvent = component.getEvent("someEventt");
    cmpEvent.fire({
        // show success message as soon as users submit
    });
},


And our apex method looks like this
 
@AuraEnabled 
public static String submit(Case caseRecord, List<String> fileNames, List<String> base64Data, List<String> contentType){
            // create case with assignment rule attached as dmlOptions
            // create ContentVersion records
            // create ContentDocumentLink records to attach the files to cases
            return caseRecord.Id;
        }
        catch(Exception ex){
            // "Convert" the exception into an AuraHandledException
            throw handleException(ex.getMessage());
        }
    }
    return '';
}

This is a web form and the returning Case ID is of no use to our guest users.
Also, they see a success message almost immediately when they submit their data, as you can see in the aura component code.

Now, where I need your help is to understand what's the best way for us to handle this situation - we don't need to wait for the response from Apex.

- Is it okay to remove the "action.setCallback()" since we simply do not need to see what comes back from salesforce?

- Move everything in the apex to a future method and immediately send back a response to aura component. I personally don't think this makes much sense because I'm sending a dummy response anyway.

Am I overlooking anything if I go with #1 or are there any better ways of handling this that I am missing.

Thanks in advance.