0

here is the full code:

import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';

import * as jsforce from "jsforce";

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {



      var conn = new jsforce.Connection({

         loginUrl : 'https://login.salesforce.com'
      });

      var username = 'XXXXXXXXXXXXXXX';
      var password = 'XXXXXXXXXXXXXXX';

      conn.login(username, password, function(err, userInfo) {
        if (err) { return console.error(err); }

            console.log(conn.accessToken);
            console.log(conn.instanceUrl);

           //this part of code works
            conn.query("SELECT Id, Name FROM Account", function(err, result) {
              if (err) { return console.error(err); }
              console.log("total : " + result.totalSize);
              console.log("fetched : " + result.records.length);
            });

           // this part of codes doesn't work
            conn.streaming.topic("InvoiceStatementUpdates").subscribe(function(message) {
              console.log('Event Type : ' + message.event.type);
              console.log('Event Created : ' + message.event.createdDate);
              console.log('Object Id : ' + message.sobject.Id);
            });

            // logged in user property
            console.log("User ID: " + userInfo.id);
            console.log("Org ID: " + userInfo.organizationId);

      });




  }

}

chrome console error log:

WebSocket connection to 'wss://ap4.salesforce.com/cometd/37.0' failed: Error during WebSocket handshake: Unexpected response code: 405
5
  • Are you sure that you call your code AFTER connection is established (f.e. in callback after login) ? – kurunve Mar 30 '17 at 15:40
  • yes all of this code is inside my constructor function and just below the login code is streaming subscription code – NavinRaj Pandey Mar 30 '17 at 15:47
  • So, is that below, or is that in callback? cause it should be like this (in very simple scenario) – kurunve Mar 30 '17 at 15:53
  • So, is that below, or is that in callback? Are you sure that subscription is being called after connection is actually established? – kurunve Mar 30 '17 at 16:00
  • I have enabled "corss-origin resource sharing" in the chrome because I couldn't connect to sf otherwise does that affect subscription?(I am testing ionic app in localhost) – NavinRaj Pandey Mar 31 '17 at 2:30

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.