Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 6 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

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 ;) – Sergey Utko 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 ;) – Phil Hawthorn Dec 21 '12 at 10:47

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.