Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <aura:component implements="flexipage:availableForAllPageTypes,lightning:backgroundUtilityItem,force:hasRecordId" access="global">
  2. <aura:attribute name="channel" type="String" required="true" default="/data/ChangeEvents" />
  3. <aura:attribute name="checkRecordId" type="Boolean" default="true" />
  4. <aura:attribute name="debug" type="Boolean" default="false" />
  5. <aura:handler name="SubscribeStreamingChannelEvent" event="c:SubscribeStreamingChannelEvent" action="{!c.handleSubscribeEvent}"/>
  6. <aura:handler name="destroy" value="{!this}" action="{!c.unsubscribe}"/>
  7. <c:StreamingChannelSubscriber channel="{!v.channel}" debug="{!v.debug}" />
  8.  
  9. ({
  10. handleSubscribeEvent : function(component, event, helper) {
  11. const debug = component.get("v.debug");
  12. const message = event.getParam('recordData');
  13. const eventType = message.payload.ChangeEventHeader.changeType;
  14. const entityName = message.payload.ChangeEventHeader.entityName;
  15. const userId = message.payload.ChangeEventHeader.commitUser.substring(0, 15); //15 digit id of transaction commit user
  16. const signedInUser= $A.get("$SObjectType.CurrentUser.Id").substring(0, 15); //15 digit id of logged in user
  17. const checkRecordId = component.get("v.checkRecordId");
  18. /**
  19. * Conditions:
  20. * - Change Type should not be create
  21. * - Record Id must present in modified recordIds
  22. * - User who modified the record should not be logged in user
  23. * */
  24. if(!(eventType === "CREATE")){
  25. //Condition 1 - Change type is not "created"
  26. Array.from(message.payload.ChangeEventHeader.recordIds).forEach( recordId => {
  27. if(debug && checkRecordId) console.log("Record Id on page = " + component.get("v.recordId") + " - Record Id in event = " + recordId);
  28. if(!checkRecordId || (checkRecordId && recordId === component.get("v.recordId"))){
  29. //Condition 2 - Record Id match found &&
  30. //Condition 3 - commit user is not logged in user
  31. //Display console log with changed values
  32. if(debug) console.log(`${eventType} event captured on ${entityName} by user id ${userId}`);
  33. if(debug) console.log("Values changed are:");
  34. }
  35. });
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement