Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

In CPQ Calculator, why is the asynchronous function returning a promise pending instead of a value?

Asked by Ishii Watanabe Feb 8, 2023 1.2K views 1 answer
Share

About this question

In the below code I am making a Server Call using async/await. Once I get the results I want to process the results and then move along after the .Then statement. The problem seems to be that Promise is still Pending so it is skipping the .Then and running the console.Log first after the .Then. How can I get the code to wait?


export function onBeforePriceRules(quote, lineModels, conn) {
let myServerResults = GetData(conn);
let ProcessResults = myServerResults;
console.log(ProcessResults) // Promise { }
ProcessResults.then(function(result) {
//Do stuff with the Results. 
console.log(result);
debugger; 
})
 console.log("New Code Block  = This is firing before my .Then Statement because Promise is still Pending But I am using async and await");
debugger; 
return Promise.resolve();
}
async function GetData(conn) {
// Await for the query results
return await conn.query("SELECT Id, Model__c FROM Product2")
.then(returnedRecords => { return returnedRecords } )
}

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.