You need to sign in to do that
Don't have an account?
Christos Kolonis
Pass JavaScript Variable To Apex Controller in LWC
Hello,
I am trying to pass a value of a variable to my apex class controller but i get that error:
el_getCustomerInvoices.js:4 Uncaught (in promise) ReferenceError: LWC component's @wire target property or method threw an error during value provisioning. Original error:
[pagePos is not defined]
My js code is this:
i need to pass the pagePos to my apex. Any ideas?
Thank you!
I am trying to pass a value of a variable to my apex class controller but i get that error:
el_getCustomerInvoices.js:4 Uncaught (in promise) ReferenceError: LWC component's @wire target property or method threw an error during value provisioning. Original error:
[pagePos is not defined]
My js code is this:
@api recordId; @api subscriptionfield=false; @api fromDT; @api toDT; @api pagePos = 0; ...... WIRE: @wire(getInvoices,{customerId: '$recordId', fromDate: '$fromDT', toDate: '$toDT',meterNum: '$selectedmeter',subscriptionNUm: '$selectedname', PagePosition: '$pagePos'}) My Apex Controller: @auraEnabled(cacheable=true) public static List<el_invoices> getInvoices(id customerId, String fromDate, String toDate, String meterNum, String subscriptionNUm, Integer PagePosition){ ....
i need to pass the pagePos to my apex. Any ideas?
Thank you!
You can try using apex:param.
References:
https://salesforce.stackexchange.com/questions/276407/pass-javascript-variable-to-apex-controller-in-lwc/276451
https://salesforce.stackexchange.com/questions/24666/how-to-pass-javascript-value-to-controller
https://developer.salesforce.com/blogs/developer-relations/2009/10/passing-javascript-values-to-apex-controller.html
Thanks,
You are likely getting this error because an error must have occurred during your wire process.
From the documentation:
data (Any type)—The value supplied by the adapter.
error (Error)—An error if the adapter wasn’t able to supply the requested data or if the adapter wasn’t found. Otherwise, this property is undefined.
What you need to do is add an
if
statement to verify ifdata
came back or not like so:Let me know if this helps