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: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 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");
public class StreamingApiController {
/**
* This method returns signed in user's session id
* @author Manish Choudhari
* */
@AuraEnabled
public static String getSessionId() {
return UserInfo.getSessionId();
}
}
//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;
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" >
<!--Include StreamingApiHandler 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:StreamingAPIHandler channelName="/topic/AccountSpy" onStreamEvent="{!c.handleMessage}" />
<lightning:card footer="Please check browser console for latest captured event"
title="Account Spy"
iconName="standard:search">
<p class="slds-p-horizontal_small">
({
handleMessage : function(component, event, helper) {
const param = event.getParam('message');
console.log(`Account "${param.sobject.Name}" with Id ${param.sobject.Id} is ${param.event.type}!!`);
}
})
{
"data":{
"event":{
"createdDate":"2018-08-22T09:06:51.980Z",
"replayId":7,
"type":"updated"
},
"sobject":{
"Type":null,
"Phone":null,
/**
* This class will run in with sharing context if
* -It is visualforce page controller
* -It is entrypoint in the transaction (like api)
* This class will run in without sharing context if
* -It is being called from another class having without shring permission
**/
public inherited sharing class InheritedSharing{
public List<Contact> getAllTheSecrets(){
/**
* Class to demo new Url.getOrgDomainUrl() and UserInfo.getSessionId() methods
*/
public class SameOrgApiDemo{
//This method will make a call to same org
public static void getOrgLimits(){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
<apex:page lightningStylesheets="true" controller="FullCalendarDemo">
<apex:stylesheet value="{!URLFOR($Resource.fullcalendar,'fullcalendar/fullcalendar.min.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.fullcalendar,'fullcalendar/jquery-ui.min.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.fullcalendar,'/fullcalendar/jquery.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.fullcalendar,'/fullcalendar/jquery-ui.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.fullcalendar,'/fullcalendar/moment.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.fullcalendar,'/fullcalendar/fullcalendar.min.js')}"/>
<apex:includeScript value="{!$Resource.FullCalendarDemo}"/>
<html>
<head>