I have the following Apex Method which is called in the Experience Cloud under unauthenticated guest user:
@AuraEnabled(cacheable=true)
public static string test(String ref) {
try {
Some_Object__c o = [Select Id, Blah__c from Some_Object__c where Blah__c =: ref];
return o.Id;
} catch (Exception e) {
System.debug(e.getMessage());
throw new AuraHandledException(e.getMessage());
}
}
Which is called by this LWC:
import { LightningElement, wire, track } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import getTest from "@salesforce/apex/SomeController.test";
export default class HelloWorld extends LightningElement {
@track ref;
@track blah;
@wire(CurrentPageReference)
getStateParameters(currentPageReference) {
if (currentPageReference) {
const urlValue = currentPageReference.state.ref;
if (urlValue) {
this.ref = urlValue;
}
}
}
connectedCallback(){
this.loadData;
}
get loadData(){
getTest({ref: this.ref})
.then(result => {
this.blah = result;
})
.catch(error => {
console.log(error);
})
}
}
The important part of this code is the loadData()
method.
Calling SomeController.Test() from this LWC results in List has no rows for assignment to SObject
. If I run this query in the developer console, I can see the value I'm passing in is there (and matches). If I run this same method anonymously, I recieve the correct result.
The parameter is populated (with some debug logs I can see it's there). If I attempt to return all rows, the list has a size of 0 (like so: List<Focus_Application__c> applications = [Select Id, Reference_Id__c from Focus_Application__c];
). I've triple checked that the custom object is definitely populated in this org.
This perhaps points to permissions on the object? But I can't see anything out of place.