Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <aura:component implements="flexipage:availableForAllPageTypes,lightning:backgroundUtilityItem,force:hasRecordId" access="global">
- <aura:attribute name="channel" type="String" required="true" default="/data/ChangeEvents" />
- <aura:attribute name="checkRecordId" type="Boolean" default="true" />
- <aura:attribute name="debug" type="Boolean" default="false" />
- <aura:handler name="SubscribeStreamingChannelEvent" event="c:SubscribeStreamingChannelEvent" action="{!c.handleSubscribeEvent}"/>
- <aura:handler name="destroy" value="{!this}" action="{!c.unsubscribe}"/>
- <c:StreamingChannelSubscriber channel="{!v.channel}" debug="{!v.debug}" />
- ({
- handleSubscribeEvent : function(component, event, helper) {
- const debug = component.get("v.debug");
- const message = event.getParam('recordData');
- const eventType = message.payload.ChangeEventHeader.changeType;
- const entityName = message.payload.ChangeEventHeader.entityName;
- const userId = message.payload.ChangeEventHeader.commitUser.substring(0, 15); //15 digit id of transaction commit user
- const signedInUser= $A.get("$SObjectType.CurrentUser.Id").substring(0, 15); //15 digit id of logged in user
- const checkRecordId = component.get("v.checkRecordId");
- /**
- * Conditions:
- * - Change Type should not be create
- * - Record Id must present in modified recordIds
- * - User who modified the record should not be logged in user
- * */
- if(!(eventType === "CREATE")){
- //Condition 1 - Change type is not "created"
- Array.from(message.payload.ChangeEventHeader.recordIds).forEach( recordId => {
- if(debug && checkRecordId) console.log("Record Id on page = " + component.get("v.recordId") + " - Record Id in event = " + recordId);
- if(!checkRecordId || (checkRecordId && recordId === component.get("v.recordId"))){
- //Condition 2 - Record Id match found &&
- //Condition 3 - commit user is not logged in user
- //Display console log with changed values
- if(debug) console.log(`${eventType} event captured on ${entityName} by user id ${userId}`);
- if(debug) console.log("Values changed are:");
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement