You need to sign in to do that
Don't have an account?
Shruti Nigam
soql query in lightning controller.js
Hi all,
Is there any way we can write soql query in lightning controller,js ?
Thanks in advance
Is there any way we can write soql query in lightning controller,js ?
Thanks in advance
you can not directly use SOQL auery in lightning javascript controller. you need to write server side controller with @auraEnabled method.
For Example:
Class:
in Component controller:
Hope this will helps you.
Thanks
karthik
You can use SOQL in java-script on your VF pages or any kind of java-script that you write, like we can get it executed on click of a button or link present on your detail page of a record. Below is the simple example and you can use it and modify it accordingly :
Javascript code:
you need to use .js files that are in first two lines in order to use the api of salesforce to connect and fetch the records using SOQL. In the example you will see result of SOQL in alert statement. The result that is returned contains a ‘records’ named array component that can be used to iterate over and go through all the records and use it in the same manner as we do in usual apex program. For ex account.id, account.Name etc.
You can also use merge fields to create dynamic queries.
Similarly, you can use javascript to create, update or delete the Salesforce object’s records using API. Below is the sample code you can use to create a new account record in your Org.
Javascript code:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha