ISSUE
The parameter name of my Apex method did not match the name of the variable when I called the method from JavaScript.
ORIGINAL QUESTION
I've never touched frontend before - I have no clue what I'm doing, so please bear with me!
So, I am trying to pass some data from a Lightning Web Component to a method in Apex.
I have console.log()'d the data just before it gets passed and it looks fine - when referencing the parameter in Apex though, it's null!
Here's the JavaScript:
1 updateBooleanSearchQuery() {
2 if (this.filters.length !== 0) {
3 let objectApiName = this.objectApiName;
4 let filters = JSON.stringify(this.filters);
5 console.log(filters);
6 getBooleanSearchText({ objectApiName, filters })
7 .then(result => {this.booleanSearchFilters = result});
8 }
[...]
console.log() on line 5 is printing:
[{"label":"Active__c : True","key":0,"value":"True","field":"Active__c"}]
But as soon as the value enters my Apex method:
1 @AuraEnabled
2 public static String getBooleanSearchText(String objectApiName, String jsonFilters) {
3 System.debug(jsonFilters);
[...]
I get this debug:
[230]|DEBUG|null
The most confusing part to me is that the exact same thing happens elsewhere and works perfectly...
1 search() {
2 this.isLoaded = !this.isLoaded;
3 console.log(this.postcode);
4 console.log(this.distance);
5 let postcode = this.postcode;
6 let distance = this.distance;
7 let objectApiName = this.objectApiName;
8 let filters = JSON.stringify(this.filters);
9 console.log(JSON.parse(JSON.stringify(this.filters)));
10 // this.updateBooleanSearchQuery();
11 searchForRecords({ objectApiName, postcode, distance, filters })
12 .then(result => {console.log(result); this.searchResults = result; this.isLoaded = false; this.resultsTitle = 'Results Found: ' + result.length;})
13 .catch(error => {console.log(error); this.error = error;});
14 }
1 @AuraEnabled
2 public static List<RadiusList> execute(String objectApiName, String postcode, String distance, String filters) {
3 System.debug(filters);
[34]|DEBUG|[{"label":"Active__c : True","key":0,"value":"True","field":"Active__c"}]
What is causing it to be null?
Please let me know if any more information is needed, I can't figure this out at all!!
filters
vs.jsonFilters
....