Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I want to select the top five opportunities. To determine top five I multiple Opportunity.Amount by Opportunity.Probability for every Opportunity and then pick out the top results.

I was hoping to do:

SELECT AccountId, Amount, Probability, (Amount * Probability) weightedProbability FROM Opportunity order by weightedProbability limit 5

which fails because it does not like:

(Amount * Probability) weightedProbability 

Any tips?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

SFDC already calculates Amount * Probability for you on the Opportunity, and stores it in the Expected Revenue field.

share|improve this answer
add comment

I would be tempted to write a formula field which performs the calculation (Amount * Probability) and then reference that in your SOQL query.

e.g.

SELECT AccountId, Amount, Probability, weightedProbability__c FROM Opportunity order by weightedProbability__c limit 5
share|improve this answer
    
lol, i will remove my answer ;) –  mast0r Dec 21 '12 at 10:37
    
@Phil Hawthorn Thanks. I'd like to be able to do it without touching the schema. Is that possible? It is in SQL but just wondering about SOQL. –  dublintech Dec 21 '12 at 10:39
1  
hmm, not that I know of I'm afraid. @mast0r, great minds think alike ;) –  user293 Dec 21 '12 at 10:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.