-
Notifications
You must be signed in to change notification settings - Fork 1
/
faq.js
42 lines (31 loc) · 1.25 KB
/
faq.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Salesforce FAQ functions.
'use strict';
const config = require('./config');
const jsforce = require('jsforce');
// New connection to Salesforce.
const conn = new jsforce.Connection(config.salesforce);
// Search FAQs for a term string.
// Callback is a function in the form function (err, result).
module.exports.search = (term, callback) => {
let query = `FIND {${term}} IN NAME FIELDS `
+ 'RETURNING FAQ__kav (Id, ArticleNumber, Title, Summary '
+ 'WHERE LANGUAGE = \'en_US\' AND PublishStatus = \'Online\') '
+ 'WITH SNIPPET';
conn.search(query, (err, res) => {
console.log(res);
callback(err, res);
});
}
// Find a single FAQ by ArticleNumber (integer).
// Callback is a function in the form function (err, result).
module.exports.findByArticleNumber = (articleNumber, callback) => {
// Left-pad ArticleNumber with zeros to create a 9-digit int as a string.
articleNumber = '000000000' + String(articleNumber);
articleNumber = articleNumber.substr(-9);
let query = 'SELECT Id, ArticleNumber, Title, Summary, Solution__c FROM FAQ__kav '
+ "WHERE Language = 'en_US' AND PublishStatus = 'Online'"
+ `AND ArticleNumber = '${articleNumber}'`;
conn.query(query, function(err, result) {
callback(err, result);
});
}