0

I have a custom numeric field: NumberOfOppsWon__c. I tried to put in some conditional logical in my email template based on its value being greater than zero.

<apex:outputPanel rendered="{!IF(relatedTo.NumberOfOppsWon__c > 0, true, false)}">
...
</apex:outputPanel>

When I try to save the email template, I get:

Error occurred trying to load the template for preview: The value 'null' is not valid for operator '>'.. Please try editing your markup to correct the problem.

Any ideas, tips?

1
  • You may want to consider adding a default value for that field; zero sounds like it would make sense.
    – Mike Chale
    Jan 2 '13 at 13:02
3

I think your NumberOfOppsWon__c field is pointing to null value and you can not compare a null with 0. you can compare like this -

<apex:outputPanel rendered="{!relatedTo.NumberOfOppsWon__c != null && 
relatedTo.NumberOfOppsWon__c > 0}">
...
</apex:outputPanel>
6
  • The IF-formula isn't really necessary if all it returns is true/false, rendered="{!relatedTo.NumberOfOppsWon__c != null && relatedTo.NumberOfOppsWon__c > 0}" should be enough. Readability is of course in the eye of the beholder, but to me that's easier to read as well. Jan 2 '13 at 13:03
  • @Pramod Kumar tried setting default value. Getting same error.
    – dublintech
    Jan 2 '13 at 13:17
  • @dublintech default value of an Integer is null thats why you are getting this error. Initialize it with 0. Jan 2 '13 at 13:20
  • @Pradmod Kumar Yes I did that. The default value is set to 0. And I get the same error.
    – dublintech
    Jan 2 '13 at 13:29
  • It should work. i have tried the same thing at my machine and it is working. Print NumberOfOppsWon__c value and see what it prints Jan 2 '13 at 13:32

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.