You need to sign in to do that
Don't have an account?
JonathanFox UK
LWC wont call Apex Method
Hi All,
Here I have a Batch Apex class which uses an API to get some random contacts. This all works perfectly fine and I am happy with it,
I wanted to trigger this with a user input via a LWC. I created BatchCreateContactController to do this.
Calling BatchCreateContactController from the Developer sonsole works, but my LWC won't call it. I suspect it is something to do with the LWC JS file. Unsure.
Here I have a Batch Apex class which uses an API to get some random contacts. This all works perfectly fine and I am happy with it,
I wanted to trigger this with a user input via a LWC. I created BatchCreateContactController to do this.
Calling BatchCreateContactController from the Developer sonsole works, but my LWC won't call it. I suspect it is something to do with the LWC JS file. Unsure.
apexImperativeMethodWithParams.js :
https://github.com/trailheadapps/lwc-recipes/blob/master/force-app/main/default/lwc/apexImperativeMethodWithParams/apexImperativeMethodWithParams.js
BatchCreateContactController.class :
public static Id initiateContactBatch(Integer numberOfRecords) {
The LWC recipe:
That is a common error because of the missing example in the documentation of LWC (the problem of the parameter passed by position only, not sufficient here).
All Answers
The position of the parameter in the method is not enough. The names of the parameters must have also exactly the same values in LWC (including the case (lower-upper)).
We can't see your code (without code, there will be few answers for your question).
apexImperativeMethodWithParams.js :
https://github.com/trailheadapps/lwc-recipes/blob/master/force-app/main/default/lwc/apexImperativeMethodWithParams/apexImperativeMethodWithParams.js
BatchCreateContactController.class :
public static Id initiateContactBatch(Integer numberOfRecords) {
The LWC recipe:
That is a common error because of the missing example in the documentation of LWC (the problem of the parameter passed by position only, not sufficient here).