Friday, June 20, 2014

How to check "undefined" in javascript in visualforce Salesforce

It is very important that if we are using javascript remoting that we check the result for undefined, as it might happen that no value is retrieved for the result and we are referring it in the page.
Take an example of this:
var res = result;
alert(res.Custom__c);
it returns "undefined" if the value of "Custom__c" is null.

To overcome this in javascript we can check the variable for typeof undefines as:

if (typeof(var) == 'undefined')  
or
if (typeof(var) != 'undefined')
Hope this helps some one :)

No comments:

Post a Comment