0

Good afternoon,

I am looking to have some of our commissions automatically calculate via Visualforce pages. I am curious what formulas are possible for outputtext fields and if those fields can be referenced elsewhere on the page.

To illustrate what I'd like to do:

apex: column headerValue="Term Modifier"

outputText value="If {!oppt.term__c = 36 then 50%

I'd then like to take that output and reference if in another column where

apex:column headerValue="Total Commission"

outputText value=" \outputtext that 50% * Amount = Commission

Is this sort of thing doable?

Thanks in advance.

0

These functions are available in Visualforce and they include logical operations like IF and CASE but using Excel-like syntax where parameters are separated by commas. Basic boolean and numeric expressions are also supported.

So your first example would be:

<apex:outputText value="{! IF(oppt.term__c == 36, '50%', '??%') }"/>

But you can't carry the result of this into another apex:outputText in the page and in any case the needs of presentation (such as displaying the text "50%") are different from the needs of calculation logic (where the number 0.5 would be more useful).

Generally, the derived values that you want to display in Visualforce pages are also needed in reports or emails. So adding formula fields to the SObject is the best way to go, leaving Visualforce to just perform the final display formatting.

Occasionally a wrapper class may make sense instead. The wrapper class would look something like this (assuming no null fields):

public class Wrapper {
    public Opportunity sob {get; set;}
    public Wrapper(Opportunity sob) {
        this.sob = sob;
    }
    public Decimal getTermModifier() {
        return sob.Term__c == 36 ? 0.5 : ??;
    }
    public Decimal getCommission() {
        return getTermModifier() * sob.Amount;
    }
}

and be returned by the controller instead of the SObject and referenced in the page like this:

<!-- Direct reference to a SObject field -->
<apex:outputText value="{! opp.sob.Amount }"/>
<!-- Reference to a derived value -->
<apex:outputText value="{! opp.commision }"/>
| improve this answer | |
  • Thank you very much for the information. It appears that I'll need to augment some of the information in VF and the object. The problem with doing these formulas on the SObjects is the character limits imposed. – Chris Nov 5 '14 at 20:04
  • Can you export visual force pages (with output Text results) to an excel file? – Chris Nov 5 '14 at 20:06
  • @Chris The formula field limits are in the thousands of characters. But if your logic exceeds that, you could use the wrapper approach. If you have one or two particularly large expressions, you can use a trigger to calculate those values and formulas to derive the rest, again making all the values available to reports etc. – Keith C Nov 5 '14 at 20:11
  • @Chris You can cut and paste a Visualforce table into Excel. But generally, if getting the data into Excel is what you are after, producing CSV output (without formatting) works best. Search this site for examples. – Keith C Nov 5 '14 at 20:13
  • Thanks @Keith C this is a huge help. Your assistance is extremely appreciated. – Chris Nov 5 '14 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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