別のクラスから呼び出された照会IDの値を取得しようとしていますが、私が期待している値ではなく約束を与える関数を呼び出します。別のクラスのpromiseチェーンから値を取得する
クラスのメソッド 'ヘルパー' は
function querySF() {
var conn = new jsforce.Connection({
// you can change loginUrl to connect to sandbox or prerelease env.
loginUrl: 'https://www.salesforce.com'
});
return conn.login('someusername', 'password')
.then(function(userInfo) {
// Now you can get the access token and instance URL information.
// Save them to establish connection next time.
console.log(conn.accessToken);
console.log(conn.instanceUrl);
// logged in user property
console.log("User ID: " + userInfo.id);
console.log("Org ID: " + userInfo.organizationId);
// ...
return conn.query("SELECT Id FROM some place Where name = 'some name'")
})
.then(function(result) {
console.log("total : " + result.totalSize);
console.log("fetched : " + result.records.length);
// is returning the id
console.log(result.records[0].Id);
return result.records[0].Id; // can see the id here when debugging
})
.catch(function(err) {
console.error(err);
});
}
を下回っている私はクラスの一番下に、次のようにモジュールを輸出しています:
exports.querySF = querySF();
他'BookingEvent'というクラスは次のようなメソッドを呼び出します:var theId = Helper.querySF;
そしてそれは約束を返します、私は約束をコンソールに出力しました
:それは私がちょうどFailed: helpers.querySF is not a function
helpers.querySF().then(function(value){
console.log(value);
})
を使用して、しかし、私はこのエラーを取得していた値を得ることができることができるはずと考えられていた
Promise {
_45: 0,
_81: 1,
_65: 'a0L46111001LyvsEAC', // This is the value I need
_54: null,
then: [Function],
stream: [Function: createRequest] }
:console.log(Helper.querySF);
は、結果を確認します
私は約束が新しく、私の会社の誰も問題を解決してくれないようです。私は約束を解決するためのさまざまな方法を研究していますが、うまくいかないし、私も理解しません。誰かがこの約束を解決するのを助けてくれたので、このメソッドを呼び出すたびにidにアクセスできるようになりました。これは、別のクエリで複数回送信されます。
これが動作するかどうかを教えてください。$ qを注入してから書き込んでみてください。return $ q.when(result.records [0] .Id); exports.querySF = querySFへのエクスポート。 –
@Galそれは問題でした、私の輸出。私は元々それを使用していたはずです。 –