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
<aura:event type="COMPONENT" description="Event template">
<aura:attribute name="empData" type="Object" />
</aura:event>
({
handleMessage : function(component, event, helper) {
const param = event.getParam('empData');
document.querySelector('#output').innerHTML +=
`<p class="slds-p-horizontal_medium">- Account "${param.sobject.Name}" with Id ${param.sobject.Id} is ${param.event.type}!!</p>`;
console.log(`Account "${param.sobject.Name}" with Id ${param.sobject.Id} is ${param.event.type}!!`);
}
})
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" >
<!--Include EmpApiDemo child component and pass channel name to subscribe
ex: "/topic/AccountSpy" is my pushtopic channel name
once the event is fired, it will handled in handleMessage controller method -->
<c:EmpApiDemo channelName="/topic/AccountSpy" onEmpEvent="{!c.handleMessage}" />
<!-- lightning card to display detail -->
<lightning:card footer="This component displays account changes using lightning:empApi component"
title="Account Spy"
({
/**
* This function calls subscribe method of empApi component
* to receive events
* @author Manish Choudhari
* @version 1.0.0
* */
subscribe: function(component, event, helper) {
// Get the empApi component.
<aura:component access="global">
<!-- ChannelName, which needs to subscribed -->
<aura:attribute name="channelName" type="String" required="true"/>
<!-- Save the reference of current subscription, which can be unsubscribe later on -->
<aura:attribute name="subscription" type="Object"/>
<!-- This event is fired when a component is destroyed.
Handle this event if you need to do custom cleanup when a component is destroyed.-->
<aura:handler name="destroy" value="{!this}" action="{!c.unsubscribe}"/>
public class LightningMapDemoController {
@AuraEnabled(cacheable=true)
public static List<CarWrapper> getAllCars(){
List<Car__c> cars = [SELECT Id, Name, Available_For_Rent__c, Build_Year__c,
Mileage__c, Per_Day_Rent__c,
(SELECT Id, Name, City__c,Coordinates__Latitude__s, Coordinates__Longitude__s,
Country__c, Pin_Code__c, State__c, Street__c FROM Address__r)
FROM Car__c Limit 100];
({
/**
* Get all cars from server
* */
getCars : function(component, helper) {
//Call server action to get events
var action = component.get("c.getAllCars");
action.setCallback(this, function(response) {
var state = response.getState();
({
/**
* Fetch car list on component initialization and
* generate datatable columns
* */
doInit : function(component, event, helper) {
component.set('v.columns', [
{label: 'Name', fieldName: 'Name', type: 'text'},
{label: 'Build Year', fieldName: 'BuildYear', type: 'number'},
{label: 'Rent/Day', fieldName: 'PerDayRent', type: 'currency',
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes"
controller="LightningMapDemoController"
access="global" >
<!-- datatable component attribute -->
<aura:attribute name="data" type="Object"/>
<aura:attribute name="columns" type="List"/>
<aura:attribute name="selectedRowsCount" type="Integer" default="0"/>
<aura:attribute name="maxRowSelection" type="Integer" default="5"/>
<apex:page lightningStylesheets="true">
<html>
<head>
<style>
.vf-header {
padding-left: 20px;
background-color: lightgrey;
padding-top: 5px;
padding-bottom: 5px;
font-weight: bold;