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 created a button which will update SAPReleased__c only if Approved__c is true(SAPReleased__c and Approved__c are both check boxes). What I don't understand is.. Why is this working!??

        if(sampling.Approved__c == 'true'){ 
        alert('Inside condition');  
        sampling.SAPReleased__c = true; 

        }else if (sampling.Approved__c == 'false'){ 
        alert('Sample must be approved before it can be booked.'); 
        var result = sforce.connection.update([sampling]); 

Now look at my conditions

if(sampling.Approved__c == 'true')
else if (sampling.Approved__c == 'false')

This doesn't make any sense to me? I am checking to see if they are 'true' or 'false', but isn't this checking to see if its a String of true or false while it should be expecting a boolean?

Is this an expected outcome or is this something cooky?

share|improve this question
up vote 7 down vote accepted

This is working because Javascript is doing the type conversion for you. You need to use a '===' to strictly evaluate a boolean like true or false. With a '==' as I understand it, type conversion has to occur before the comparison can be evaluated and type conversion can lead to strange results. In this case though, it's leading to your intended result, which is conversion from boolean to string and the correct evaluation.

Here is a pretty good blog post explaining different equals operators in Javascript: Why Use the Triple-Equals Operator in JavaScript?

share|improve this answer
It is so I will leave alone, it's just very interesting.. – EricSSH Apr 14 '14 at 22:40

Your Answer


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.