Skip to content

Commit

Permalink
Added namespace fix and record id check
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulmalhotra committed Oct 3, 2021
1 parent 9a28106 commit 12c1c36
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
* Author:- Rahul Malhotra
* Description:- Platform Event Toast
* Created:- 11/04/2020
* Last Updated:- 12/04/2020
* Last Updated:- 03/10/2021
* Code Origin:- SFDCStop (https://www.sfdcstop.com/)
* Change Log
* ----------
* SNo. Date Description
* 1 03/10/2021 Added namespace fix and record id check
*/
import { LightningElement, api } from 'lwc';
import { subscribe, unsubscribe, onError } from 'lightning/empApi';
Expand All @@ -18,6 +22,7 @@ export default class PlatformEventToast extends LightningElement {
@api toastVariant;
@api toastMode;
@api runInSystemMode;
@api recordId;
channelName = '/event/ToastEvent__e';
subscription = {};

Expand All @@ -26,13 +31,19 @@ export default class PlatformEventToast extends LightningElement {
const ci = this;
const toastCallback = function(response) {
let toastData = response['data']['payload'];
if(toastData) {
toastData = ci.checkForNameSpace(toastData);
}
if(
toastData &&
toastData['Key__c'] &&
ci.toastKeys.includes(toastData['Key__c']) &&
(
ci.runInSystemMode ||
(toastData['CreatedById'] === currentUserId)
) &&
(
toastData['RecordId__c'] && ci.recordId ? toastData['RecordId__c'] === ci.recordId : true
)
) {
const toastEvent = new ShowToastEvent({
Expand Down Expand Up @@ -60,4 +71,26 @@ export default class PlatformEventToast extends LightningElement {
console.log(response);
});
}

checkForNameSpace(oldRecord) {
let newRecord = {};
for(let key in oldRecord) {
if(key.includes('Message__c')) {
newRecord['Message__c'] = oldRecord[key];
} else if(key.includes('Variant__c')) {
newRecord['Variant__c'] = oldRecord[key];
} else if(key.includes('Mode__c')) {
newRecord['Mode__c'] = oldRecord[key];
} else if(key.includes('Title__c')) {
newRecord['Title__c'] = oldRecord[key];
} else if(key.includes('Key__c')) {
newRecord['Key__c'] = oldRecord[key];
} else if(key.includes('RecordId__c')) {
newRecord['RecordId__c'] = oldRecord[key];
} else {
newRecord[key] = oldRecord[key];
}
}
return newRecord;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>RecordId__c</fullName>
<description>Id of the record</description>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Record Id</label>
<length>18</length>
<required>false</required>
<type>Text</type>
<unique>false</unique>
</CustomField>

0 comments on commit 12c1c36

Please sign in to comment.