I have basically a simple custom made button that needs to auto submit the account for approval like standard functionality button but with specific comments added.

import { LightningElement, track, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { updateRecord } from 'lightning/uiRecordApi';

import startApproval from '@salesforce/apex/LWCSubmitForApproval.approvalInit';
import getApprovalComments from '@salesforce/apex/LWCSubmitForApproval.getApprovalComments';

export default class lwcSubmitForApproval extends LightningElement {

    @track startApproval;
    @track disabled = false;
    @track error;

    @api recordId; // Account Id

    @wire(getApprovalComments, { accId: '$recordId' })

    get approvalComments(){
        return this.approvalCommentsWired && this.approvalCommentsWired.data;

    // onclick button handler
    submitForApproval() {
        startApproval({ accId: this.recordId, comment: this.approvalCommentsWired.data }).then(result =>{
                this.showSpinner = false;
            this.showSpinner = false;
        }).catch(error => {
            this.error = error;
            this.showSpinner = false;


+++ apex class

 * Created by 13ent on 8/13/2020.

public with sharing class LWCSubmitForApproval {

    ** This method initiates an approval process for the given object
    public static void approvalInit(String accId, String comment){
        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
        Approval.ProcessResult result;
            // submit the approval request for processing
            result = Approval.process(req);
        }catch(Exception e){
            System.debug('No approval process has been setup yet.');

I am not getting any response from clicking the button calling the submitForApproval() method. Any idea why? How to call my apex class so that it works?

1 Answer 1


Your method returns void (no value), and you're swallowing errors (never do this!). You should throw a new exception to invoke the error handler if you have an error:

}catch(Exception e){
    throw new AuraHandledException(e.getMessage());

This will allow you to detect if there's an error.

Note that if then is called, then there was no fatal exception. There's no need to check if(result) for a void return type, as there will never be a result.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .