In Salesforce.com, I've created a custom detail page button that will create a new Case record from a custom object. All is working well, until I tried to add a piece that sets a checkbox field on Case to true when a number field on the custom object is less than a specific number.

Here is the code snippet that isn't working:

  if("{!Form__c.Volume__c}" < 3000000)
        c.SmallVol__c = true;

If I replace the number field with a text field, the SmallVol field gets populated as expected:

  if("{!Form__c.testtext__c}" == "abc123")
        c.SmallVol__c = true;

Any pointers or ideas? Thanks in advance!

  • throw this line in alert('Inside the IF!');
    – EricSSH
    Jul 28, 2014 at 23:31
  • The alert does not pop up in the first code snippet (number). When using it in the second (text), it does.
    – Aaron
    Jul 28, 2014 at 23:47
  • It must have something to do with this piece: "{!Form__c.Volume__c}". It is a number field for sure, and I also tried without the double quotation marks, but no luck.
    – Aaron
    Jul 29, 2014 at 0:19
  • "{!Form__c.Volume__c" evaluates in java to "12345" as a string. Since you said you tried without the quotes try Number("{!Form__c.Volume__c}")
    – Eric
    Jul 29, 2014 at 0:29

1 Answer 1


Remove the string speechmarks from around your variable declaration like so:

if({!Form__c.Volume__c} < 3000000)
    c.SmallVol__c = true;

As noted in the comments below, to confirm that the value in {!Form__c.Volume__c} is in fact a number as expected, it can be helpful to examine the JavaScript output on the page.

Salesforce takes the expression inside the curly braces, evaluates it (compiles it, really) and places the result of that expression in place of the curly brace expression. In this instance, I'd expect {!Form__c.Volume__c} to equal some numeric value, like 2000000.

Because we are dealing with formatted output, sometimes this numeric value gets formatted into a string, for example as shown in the comments, 2000000 becomes '2,000,000' which of course will not work in the above if statement.

To get to this JavaScript, you use a JavaScript developer console, available in most browsers. To access the developer console (I find Chrome's one is the easiest to use), right click on an html element and click "Inspect Element". It's not important exactly which element you click on, as you are really interested in your JavaScript.

Look around and you'll find your code inside a <script> element. From here, you should be able to confirm exactly what your curly braces expression has evaluated to.

  • Unfortunately, that didn't work either, however, the comments from all have pointed me into the right direction and I have found that this works: "{!VALUE(TEXT(Form__c.Volume__c))}"
    – Aaron
    Jul 29, 2014 at 0:48
  • 1
    That seems very strange to me. If you open up the page in your JavaScript developer console and put in a breakpoint at this point in the code, I'd be interested to see what the two values are. I'd say that the only reason it's working is that JavaScript is implicitly converting your string value to a number and it's less than 30000000. Jul 29, 2014 at 1:00
  • Indeed, I figured I'm comparing 2 numbers so shouldn't have to convert. Unfortunately, I'm not a developer at all and know just enough to be dangerous. How would I go about checking this in developer console as you suggested? When I use if({!Form__c.Volume__c} < 3000000), the checkbox on the case record is set to true whether the Volume is smaller or larger than 3,000,000. If I use if("{!VALUE(TEXT(Form__c.Volume__c))}" < 3000000), the checkbox gets updated as expected. Thanks again for your help!
    – Aaron
    Jul 29, 2014 at 23:22
  • To access the developer console (I find Chrome's one is the easiest to use), right click on an html element and click "Inspect Element". It's not important exactly which element you click on, as you are really interested in your javascript. It's a little hard to find your way around at this point, but eventually (perhaps with some google searching), you'll find your code inside a <script> element. Look for the {!Form__c.Volume__c} statement and see what Salesforce has replaced that value with - it should be a number value. Let me know what you find. Jul 30, 2014 at 1:36
  • Aha! The value in the field shows as 2,000,000. It includes the the thousand separator. This is how it is displayed on the page, however when extracting the data, it shows as 2000000. Thanks again CaspNZ. Your guidance is very much appreciated. I'm getting more dangerous by the day ;-). - BTW, if you would like to post a short synopsis of our findings, I'd be happy to mark your answer so you get the credit.
    – Aaron
    Jul 30, 2014 at 4:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .