-
Go into the
salesforce_app
foldersfdx force:org:create -f config/project-scratch-def.json --durationdays 30 -a <<TargetOrgAlias>>
sfdx force:source:push -u <<TargetOrgAlias>>
-
You will have a Lightning App Page called
PubSub_Demo
or you can simply drag and drop the componentPubSub Chat Messenger
on any page layout. -
A Platform Event Object named
PubSubMessage__e
will need to be deployed. -
Fields :
- Message__c
- Source__c
- UUID__c
This will be Setup so we can seperate between inbound to outbound messages
-
Generate a Security Token or setup a Connected App to allow login in to this scratch org.
-
Setup your authentication credentials
sfdx force:user:password:generate -u <<TargetOrgAlias>>
sfdx force:user:display -u <<TargetOrgAlias>>
-
Login into your new scratch org
-
sfdx force:org:open -u <<TargetOrgAlias>>
-
Got into
User settings > My Personal Information > Reset Security Token
to get a new security token, this will be sent by email. -
Copy All those User details into your
.env
file
- Publish Event
const userAlias = 'SF'; // SF / PC Depends on current user
const messageValue = 'Our message';
const publishRequest = {
objectApiName: 'PubSubMessage__e',
fields: [{
key: 'Source__c',
value: userAlias
},
{
key: 'Message__c',
value: messageValue
},
{
key: 'UUID__c',
value: createUUID()
}
]
}
- Subscribe and Parse Response
let items = [];
// Construct posts from payload
const { schema, fields, payload, event } = record;
// Format Platform Event fields
let record = fields && fields.length ? fields.reduce((obj, field) => { obj[field.key] = field.value; return obj; }, {}) : null;
items.push({
from: record.Source__c,
message: record.Message__c,
date: payload.CreatedDate,
uuid: record.UUID__c
});