在Javascript函数中从SOQL查询返回Count()
我正在尝试返回与Opportunity相关的ProductName=EAP的产品数。这是我的密码:在Javascript函数中从SOQL查询返回Count(),javascript,salesforce,soql,Javascript,Salesforce,Soql,我正在尝试返回与Opportunity相关的ProductName=EAP的产品数。这是我的密码: function getProductTypes (oppId) { var result = sforce.connection.query("Select COUNT() From OpportunityLineItem where OpportunityId = '" + oppId + "' and PricebookEntry.Product2.Name IN ('EAP') ");
function getProductTypes (oppId) {
var result = sforce.connection.query("Select COUNT() From OpportunityLineItem where OpportunityId = '" + oppId + "' and PricebookEntry.Product2.Name IN ('EAP') ");
return result;
}
我要做的是返回与opportunity相关的“EAP”产品的数量,以便在下面的代码块中,我可以确定要运行的另一段代码:
if(getProductTypes('{!Opportunity.Id}') >= 1){
//run this code!
}else{
//run this code instead!
}
如有疑问-
alert()
或console.log()
是您最好的朋友;)紧随其后的是对象的规范(它位于与AJAX工具包开发人员指南不同的文档中…)
这应该起作用:
function getProductTypes (oppId) {
var result = sforce.connection.query(...);
alert(result); // remove it once you're happy
return result == null ? 0 : result.size;
}