1

Good morning,

I'm trying to send Platform Events to salesforce using a Platform app from Azure and I'm receiving that everything it's ok but no other log and not a single platform event was created.

This is the code on my Platform App and every parameter is matching with Salesforce Parameter


module.exports = function (context, eventHubMessages) {
   context.log(`JavaScript eventhub trigger function called for message array ${eventHubMessages}`);

    var nforce = require('nforce');
   // saleforce log in details
   var SF_CLIENT_ID ='<Clietn Id>';
   var SF_CLIENT_SECRET = '<Client secret>;
   var SF_USERNAME = '<my user>';
   var SF_ENVIRONMENT = 'Production';
   var SF_PASSWORD_FULL = '<my password>'; //3yKJAoNp6ONzzLKt5QGz7b7m6';
   var SF_CALLBACK_URL = 'http://localhost:3000/oauth/_callback';
   var org = nforce.createConnection({
       clientId: SF_CLIENT_ID,
       clientSecret: SF_CLIENT_SECRET,
       redirectUri: SF_CALLBACK_URL,
       environment: SF_ENVIRONMENT,
       mode: 'single'
   });
   org.authenticate({ username: SF_USERNAME, password: SF_PASSWORD_FULL},
   function(err, resp){
       if(!err){
          context.log('Successfully');
          context.log('Successfully connected to Salesforce, Cached token: ' + org.oauth.access_token);
          context.log(eventHubMessages[0]);
          var jsonMsg=JSON.stringify(eventHubMessages[0]);
          var jsonObj= JSON.parse(jsonMsg);
          //CREATE DrinksMachine Platform Event
          var evt = nforce.createSObject('Asset_platform_event__e');
          evt.set('Asset_Id__c',jsonObj.Asset_Id__c);
          evt.set('Temperature__c',jsonObj.Temperature__c);
          evt.set('Pressure__c',jsonObj.Pressure__c);
          org.insert({ sobject: evt }, function(err, resp){
          if (!err) {
                   context.log('SUCCESS :: Platform Event Sent');
          }
          else {
                   context.log(err);
                   context.log('prueba');       }
          });

       }

       else {
                   context.log('Cannot connect to Salesforce: ' + err);
                   context.log('prueba2');    }
   });
   context.log(`Processed message ${eventHubMessages}`);
   context.done();
};

I'm receiving this log

2019-12-23T20:46:08.893 [Information] Executed 'Functions.EventHubTrigger1' (Succeeded, Id=6ba4111b-fe15-43c1-a2c6-b517fcfd6bdf) 2019-12-23T20:47:53.513 [Information] Executing 'Functions.EventHubTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=6d2ba5d6-6220-470d-9b91-eee64e65ec6a) 2019-12-23T20:48:28.340 [Information] JavaScript eventhub trigger function called for message array [object Object] 2019-12-23T20:48:28.341 [Information] Processed message [object Object] 2019-12-23T20:48:28.342 [Information] Executed 'Functions.EventHubTrigger1' (Succeeded, Id=6d2ba5d6-6220-470d-9b91-eee64e65ec6a)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.