Skip to content

Instantly share code, notes, and snippets.

View choudharymanish8585's full-sized avatar
💭
Never Settle

Manish Choudhari choudharymanish8585

💭
Never Settle
View GitHub Profile
public with sharing class CarSearchController {
@AuraEnabled
public static List<Car__c> getCars(String carTypeId){
//If 'All Type' selected on UI, below code will execute to get all cars
if(carTypeId.equalsIgnoreCase('')){
return [SELECT id, Name, Picture__c, Contact__r.Name,
Geolocation__latitude__s, Geolocation__longitude__s
FROM Car__c
WHERE Available_For_Rent__c = true ];
({
onSearch : function(component, helper) {
/*helper.callServer(component, "c.getCars",
function(response){
//console.log("response---"+JSON.stringify(response));
if(response.length >0 ){
component.set("v.cars", response);
component.set("v.carFound", true);
}
({
doInit : function(component, event, helper) {
helper.onSearch(component, helper);
},
doSearch : function(component, event, helper) {
//this line will get all the argument passed to aura:method
var params = event.getParam('arguments');
//checking if param is not undefined
<aura:component implements="force:appHostable" extends="c:Base" controller="CarSearchController">
<aura:attribute type="Car__c[]" name="cars" access="public" />
<aura:attribute type="String" name="carTypeId" access="private" default="" />
<aura:attribute type="boolean" name="carFound" access="private" default="false" />
<aura:attribute type="Id" name="selectedCarId" access="public"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}" />
<!-- this event is being fired by nested CarTile component
({
doFormSubmit : function(component, event, helper) {
//fetching carTypeId attribute value from event
var carTypeId = event.getParam('carTypeId');
var carSearchResultComp = component.find("carSearchResult");
// call the aura:method in the child component
var carSearchCmpResult = carSearchResultComp.searchCars(carTypeId);
console.log("auraMethodResult: " + carSearchCmpResult);
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">
<!-- searchFormSubmit event handler to call aura method 'searchCars' of
CarSearchResult component -->
<aura:handler name="searchFormSubmit" event="c:SearchFormSubmitEvent" action="{!c.doFormSubmit}" />
<!-- Top CarSeachForm Component -->
<lightning:card title="Search Your Car" class="bottom_margin">
<c:CarSearchForm />
</lightning:card>
({
getCarType : function(component, helper) {
/*
* Below line of code uses inheritance to
* call server side controller from
* base component's helper method
* */
helper.callServer(component, "c.getCarTypes",
function(response){
({
doInit : function(component, event, helper) {
var createBoatRecord = $A.get("e.force:createRecord");
if(createBoatRecord){ //check if this event is available or not
component.set("v.showNew", true);
} else{
component.set("v.showNew", false);
}
helper.getCarType(component, helper);
<aura:component controller="CarTypeSearch"
implements="force:appHostable,flexipage:availableForRecordHome,force:hasRecordId"
extends="c:Base">
<!-- Attribute to controle visibility of New button -->
<aura:attribute name="showNew" type="boolean" />
<aura:attribute name="carTypes" type="Car_Type__c[]"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:component abstract="true">
{!v.body}
</aura:component>