jsforce
jsforce copied to clipboard
query function is taking 1-3 seconds to return results
Hello,
I am trying below function to get list of Accounts and their opportunities matching searchInput
and found that its taking around 1-3 seconds and sometimes around 6 seconds to get the reply from Salesforce.
const conn = new jsforce.Connection({
oauth2: {
clientId: KINTENT_SALESFORCE_CLIENT_ID,
clientSecret: KINTENT_SALESFORCE_CLIENT_SECRET
redirectUri: KINTENT_SALESFORCE_REDIRECT_URI
},
...remainingSettings
});
const response = await conn.query("select name, id, (select id, name from opportunities) from account where name = 'test'");
console.log('Response', response);
If I run following REST API through Postman I am getting response in less than 500ms
, so I would like to know is there anything I am doing wrong because of which I am getting response after 1-2 seconds?
https://<instance-url>/services/data/v43.0/query?q=select name, id, (select id, name from opportunities) from account where name = 'test'
Can anybody please help?
Depending on how you are authorizing, if your accessToken is expired and you are not storing the updated token after a refresh, then you might fall into this flow:
- attempt query, 401 for invalid token
- jsforce goes through refresh flow
- attempt query again
You can to do this to see if you are indeed hitting that flow
conn.on("refresh", function(accessToken, res) {
console.log('REFRESH TOKEN WAS OBTAINED');
});
You can also set the logLevel
to DEBUG to see if there is anything else - not sure if you will find anything http://jsforce.github.io/jsforce/doc/Connection.html
Other than that, I am not sure.
Thank you for quick reply @paustint ,
I am using latest token and I have enabled logLevel
to DEBUG
as you suggested.
Here are the logs I received on console
>>> Query start >>>
SOQL = select name, id, (select id, name from opportunities) from account where name = 'test'
<request> method=GET, url=https://<instance-url>.salesforce.com/services/data/v42.0/query?q=select%20name%2C%20id%2C%20(select%20id%2C%20name%20from%20opportunities)%20from%20account%20where%20name%20%3D%20'test'
elapsed time : 2102msec
<response> status=200, url=https://<instance-url>.salesforce.com/services/data/v42.0/query?q=select%20name%2C%20id%2C%20(select%20id%2C%20name%20from%20opportunities)%20from%20account%20where%20name%20%3D%20'test'
*** Query finished ***
Apart from these there are no other logs on the console.
Hmm, that does seem odd. I have tested with username+password as well as oauth and see generally consistent results with query() and hitting the endpoint directly.
Sorry I couldn't have been more helpful.
Okay @paustint , I have tried using different method for querying like
const response = await conn.sobject('Account')
.find({ Name: { $like: `%${name}%` } }, 'Id, Name')
.include('Opportunities').select('Id, Name, CreatedDate, CloseDate, Amount')
.execute();
The behaviour is same though.
Can anybody else help? this is really a blocker.