1

I am trying to return the number of products of with the ProductName = EAP related to an Opportunity. Here is my code:

function getProductTypes (oppId) { 

var result = sforce.connection.query("Select COUNT() From OpportunityLineItem where OpportunityId = '" + oppId + "' and PricebookEntry.Product2.Name IN ('EAP') "); 

return result; 

} 

What I want to do is return the number of number of "EAP" products related to the opportunity so then in the below code block, I can determine another piece of code to run:

if(getProductTypes('{!Opportunity.Id}') >= 1){ 
//run this code!
}else{
//run this code instead!
}

1 Answer 1

1

In case of doubt - alert() or console.log() is your best friend ;) Closely followed by specification of the QueryResult object (it's in different document than the AJAX toolkit developer guide...)

This should work:

function getProductTypes (oppId) { 

    var result = sforce.connection.query(...);

    alert(result); // remove it once you're happy
    return result == null ? 0 : result.size;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.