react-redux-blog-vf icon indicating copy to clipboard operation
react-redux-blog-vf copied to clipboard

Question about JS Force connection credentials

Open CoralSilver opened this issue 8 years ago • 3 comments

Thanks for the great repo and tutorial. I'm brand new to Salesforce development. In posts.js you have a hard coded serverUrl and SessionId. I imagine these need to be changed? How do I get a sessionId? Do I need to pass in a dynamic id? Thanks.

CoralSilver avatar Mar 13 '17 20:03 CoralSilver

if its a dev org , you can replace the connection line with the below code. var conn = new jsforce.Connection({ loginUrl: 'https://login.salesforce.com' });

conn.login('yourusername', 'yourpassword+securitytoken');

you might have to open a new terminal to run the npm start command for the API server to run.

siddharatha avatar Mar 16 '17 13:03 siddharatha

Thanks. What about when it is deployed to production?

CoralSilver avatar Apr 05 '17 20:04 CoralSilver

@CoralSilver you would need this in your dev environment because you are using API calls to replicate the behaviour of remote objects by creating an api server locally . You are having to use the org credentials only during development , if you look at the code of index.js in public/src/api


import axios from 'axios';

const inVF = location.href.indexOf('apex') > 0 ? true : false;
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:3000/api' : '/api';

export function getPosts() {
  if (!inVF) { //local - use axios
    return axios.get(`${ROOT_URL}/posts?query=SELECT Id, Name,Categories__c FROM Post__c`);
  }

return new Promise((resolve, reject) => {    
var post = new SObjectModel.Post();

you can refer to remote objects for more details.

siddharatha avatar Apr 10 '17 07:04 siddharatha