I am trying to use streaming API feature of salesforce, and be able to subscribe to the topic in an external client which is HTML based.
My code is below:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsforce/1.9.1/jsforce-core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsforce/1.9.1/jsforce-api-streaming.min.js"></script>
<script>
function myFunction() {
var jsforce = require('jsforce');
var username = 'XXXXX';
var password = 'YYYYY';
var securityToken = 'ZZZZZ';
const conn = new jsforce.Connection({loginUrl : 'https://test.salesforce.com'});
conn.login(username, password + securityToken, function(err, res) {
if (err) {
return console.error(err);
}
console.log('Authenticated');
conn.streaming.topic("PushTopicUpdates").subscribe(function(message) {
console.log('Event Type : ' + message.event.type);
console.log('Event Created : ' + message.event.createdDate);
console.log('Object Id : ' + message.sobject.Id);
console.log('Event : ' + JSON.stringify(message));
});
});
}
</script>
</head>
<body onload="myFunction()">
</body>
</html>
I am getting an error as below:
Uncaught ReferenceError: require is not defined
at myFunction (StreamingAPI.html:8)
at onload (StreamingAPI.html:31)