react-redux-blog-vf
react-redux-blog-vf copied to clipboard
Question about JS Force connection credentials
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.
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.
Thanks. What about when it is deployed to production?
@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.