Skip to main content

I can't seem to figure out how to get this to work. 

 

My original intent is to input parameters into LWC component lightning input fields which values will be passed to the batch class aura-enabled method. I don't need to return anything (I simply want to execute the apex class), though I am returning a list to stick to the return data requirements (as I understand it to be a requirement).

 

The apex class works when instantiated and called in the dev console anonymous window.

Debug logs indicate that the batch class is never called from LWC.

The button is working and responding in the developer window.

Attempting to Call Batchable Apex Method

 

Debug Logs - Class Is Not Called.png

 

Widget Screenshot.png

Relevant code:

 

html

<lightning-button label="Batch Delete Records" onclick={handleClick}> </lightning-button>

<p>Returned data array: {accounts}</p>

Javascript

handleClick(event)

{

this.clickedButtonLabel = event.target.label;

console.log('clickedButtonLabel >>> '+this.clickedButtonLabel);

callMethod,{js_obj: '$html_obj', js_year: '$html_year', js_month: '$html_month', js_day: '$html_day', js_deleteAllRecords: '$value'}

.then(result => {

this.accounts = result;

this.error = undefined;

}).catch(error => {

this.error = error;

this.accounts = undefined;

})

}

Apex

@AuraEnabled

public static List<string> callMethod(String js_obj, Integer js_year, Integer js_month, Integer js_day, Boolean js_deleteAllRecords){

try {

batch_DeleteByObjCreatedDateOrAll callClass = new batch_DeleteByObjCreatedDateOrAll(js_obj, js_year, js_month, js_day, js_deleteAllRecords);

Database.executeBatch(callClass);

List<String> randomList = new List<String>();

randomList.add('first');

randomList.add('second');

randomList.add('third');

return randomList;

} catch (Exception e) {

throw new AuraHandledException(e.getMessage());

}

}

4 réponses
0/9000