1

So I am working with JSforce lib and I am loging into SFDC by using this code which works perfectly but the problem is when the popup opens and get the access token in the URL nothing happens next the popup never closes and browser.on function never fires.

<apex:page showHeader="false" standardStylesheets="false">
<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jsforce/1.3.1/jsforce.min.js"></script>
<script>

jsforce.browser.init({
  clientId: '3MVG9Y6d_Btp4xp7mLm_Hzhxc2gM.QMsZhKWDrFhNZ8zSJHS1rGKyuXrTR_XCszTknzUW_xA6mXSVtss9buDF',
  redirectUri: 'https://c.ap1.visual.force.com/apex/JSForce_authrization',
  proxyUrl: 'https://c.ap1.visual.force.com/apex/JSForce_authrization'
});

jsforce.browser.on('connect', function(conn) { 
    alert();
});

</script>
</head>
<body>
  <button onclick="jsforce.browser.login();">Login</button>
</body>
</html>
</apex:page>

The code above does call the authorization but the popup window does not close after it nor the browser.on fires any comments!! enter image description here

1
  • So the trick is to disable the developer mode as it is a iframe and due to this the jsforce.js was not able to identify where to fire the "connect" event to..
    – user614946
    Commented Oct 8, 2014 at 5:12

2 Answers 2

1

Disable the Salesforce "Development Mode" or login as a user.

"Development Mode" is a reference to Salesforce Development Mode. See the following two pages for more information about it:

5
  • A good way to know when to answer or comment is to consider how sure you are. If you are suggesting to "try" things, you're still debugging/analysing the issue and it's recommended to comment. Commented Oct 7, 2014 at 7:22
  • 1
    Thanks @Arun SFDC now the popup is closing as expected!!
    – user614946
    Commented Oct 7, 2014 at 8:42
  • Please mark as solved if my answer solved.
    – Arun SFDC
    Commented Oct 7, 2014 at 8:46
  • Hi @user614946, as Arun says, can you mark the answer as accepted if that fixed it? Also, can you clarify what it was? i.e. development mode/logging as another user.
    – Matt Lacey
    Commented Oct 7, 2014 at 10:59
  • "Development Mode" is a reference to Salesforce Development Mode. See the following two links for details. help.salesforce.com/apex/HTViewHelpDoc?id=pages_dev_mode.htm developer.salesforce.com/docs/atlas.en-us.workbook.meta/…
    – Jon Freed
    Commented May 4, 2016 at 23:32
1

I'm author of JSforce, few comments :

  • Why are you using jsforce.browser object in Visulaforce page ? jsforce.browser is needed for external web apps that needs to be authorized to access to Salesforce API via OAuth2. Visualforce pages are always authorized and can use access token (session id).

    var conn = new jsforce.Connection({ accessToken: "{!API.Session_Id}" });

  • I'm not sure the implementation at the endpoint URL proxyUrl in jsforce.browser.init. It is used for specifying Salesforce Ajax Proxy compatible proxy service URL. As the same URL is specified in redirectUri, I'm doubting it is misused.

1
  • Hi Thanks for the comments It really helped. The resion I used this approach as this page will be hosted through sites and a User might not be a User in my own org. Also I removed the proxy URL from my code. Thanks
    – user614946
    Commented Oct 10, 2014 at 5:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .