This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Run this code in anonymous window of developer console | |
//Here my channel name is "AccountSpy" which will be used for subscription | |
PushTopic pushTopic = new PushTopic(); | |
pushTopic.Name = 'AccountSpy'; | |
pushTopic.Query = 'SELECT Id, Name, Type, Phone, Website FROM Account'; | |
pushTopic.ApiVersion = 43.0; | |
pushTopic.NotifyForOperationCreate = true; | |
pushTopic.NotifyForOperationUpdate = true; | |
pushTopic.NotifyForOperationUndelete = true; | |
pushTopic.NotifyForOperationDelete = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StreamingApiController { | |
/** | |
* This method returns signed in user's session id | |
* @author Manish Choudhari | |
* */ | |
@AuraEnabled | |
public static String getSessionId() { | |
return UserInfo.getSessionId(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
/** | |
* This function makes a handshake request to server using current user's session id | |
* Once the handshake is complete, susbcribe to the channel | |
* @author Manish Choudhari | |
* @version 1.0.0 | |
* */ | |
doInit: function(component, event, helper) { | |
//Call server action to get current user's session id | |
var action = component.get("c.getSessionId"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component access="global" controller="StreamingApiController"> | |
<!-- ChannelName, which needs to subscribed --> | |
<aura:attribute name="channelName" type="String" required="true"/> | |
<!-- Save the reference of cometD, which will be used to disconnect the subscription --> | |
<aura:attribute name="cometd" type="Object"/> | |
<!-- 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}"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:event type="COMPONENT" description="Capture streaming api event. Takes message object parameter"> | |
<aura:attribute name="message" type="Object" /> | |
</aura:event> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AccountController { | |
@AuraEnabled | |
public static List<Account> getAccounts(){ | |
return [SELECT | |
Id, Name, Phone, Rating, My_Custom_Field__c, Active__c | |
FROM Account LIMIT 200]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
getAllAccounts : function(component, helper) { | |
//Calling base component's helper method to call Aura Method | |
helper.callServer(component, "c.getAccounts", | |
function(response){ | |
if(response){ | |
component.set("v.data", response); | |
//Calling showToast method of Base component | |
helper.showToast({ | |
"title": "SUCCESS", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(component, event, helper) { | |
helper.getAllAccounts(component, helper); | |
}, | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Exntends Base Component in Component Definition --> | |
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" | |
extends="c:Base" controller="AccountController" access="global" > | |
<aura:attribute name="data" type="Account[]"/> | |
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/> | |
<aura:iteration items="{!v.data}" var="acc"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
/* | |
* This method will call the server side action and will execute callback method | |
* it will also show error if generated any | |
* @param component (required) - Calling component | |
* @param method (required) - Server side methos name | |
* @param callback (required) - Callback function to be executed on server response | |
* @param params (optional) - parameter values to pass to server | |
* @param setStorable(optional) - if true, action response will be stored in cache | |
* */ |