You need to sign in to do that
Don't have an account?
Dev Raul
Pass query parameters from component and display results
Hi all,
I would like to make a query through a lightning component.
This component should have some input parameters like fields to choose/insert (SELECT), object selection/input (FROM), and maybe a where condition.
Then, I would like to display the query result in another page.
I don't know how to insert parameters in a lightning component, pass them to a controller and make a query.
Is that possible? Could you give me some advise?
Thank you very much, any help would be very appreciated.
Raul
I would like to make a query through a lightning component.
This component should have some input parameters like fields to choose/insert (SELECT), object selection/input (FROM), and maybe a where condition.
Then, I would like to display the query result in another page.
I don't know how to insert parameters in a lightning component, pass them to a controller and make a query.
Is that possible? Could you give me some advise?
Thank you very much, any help would be very appreciated.
Raul
try below code and fatch dynmic records of object by passing some parameters from Component and make query. you need to pass objectApiName and some fields name that you want to pass.
//Here is apex class take reference from above code and don't forget to mark it as best answer.
Thank you
Thank you very much for your reply. I saw your code, but this does not allow me to input parameters and to have search results after, in another page. Could you help me also with that?
Thank you again.
use my code to understand the flow between Component,JS,Class.
Que--> Create an aura component that will use to create a new account with five fields values.
Ans:
Step 1: Create a Lightning Component
<aura:component controller="AccountInsertController">
<aura:attribute name="acc" type="Account" default="{'sObjectType': 'Account'}"/>
<div>
<div>
<lightning:input label="Account Name" value="{!v.acc.Name}"/>
</div>
<div>
<lightning:input label="Account Description" value="{!v.acc.Description}"/>
</div>
<div>
<lightning:input label="Account Year Started" value="{!v.acc.YearStarted}"/>
</div>
<lightning:button label="Save" onclick="{!c.Save}"/>
</div>
</aura:component>
Step 2: Create a Lightning Controller for the component
({
Save : function(component, event, helper) {
helper.help(component)
}
})
step3: Create Helper Controller
({
help : function(cmp){
var action=cmp.get("c.insertAccount");
action.setParams({acc : cmp.get("v.acc")});
action.setCallback(this,function(response){
var state=response.getState();
if(state=="SUCCESS"){
alert("From Server: " +response.getReturnValue());
}
else if(state=="ERROR"){
var errors=response.getError();
alert(JSON.stringify(errors));
}
});
$A.enqueueAction(action);
}
})
step 4 Create an Apex class and define the method to create the record
public class AccountInsertController {
@AuraEnabled
public static id insertAccount(Account acc){
insert acc;
return acc.id;
}
}
Step 5: Create a Lightning application which will host the component in the App
<aura:application extends="force:slds">
<c:InsertNewAcc/>
</aura:application>
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi