function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MasahiroYMasahiroY 

How to check if the Integer is blank?

I'm working on Apex, and enconuter a problem how to check the blank value in integer varibale. Here're the codes.

Pass the number input from lightning:input to Apex Class.
component
<aura:attribute name="searchValue" type="Integer"/> 
                <div class="flex-item space-digit text-overflow-hide">
                <lightning:input
                    type="number"
                    name="Limit"
                    label="Value"
                    value="{!v.searchValue}"
                    onchange="{!c.onSearchTermChange}"
                />
                </div>


 
Switch the condition query in Dynamic SOQL, if !=null, then skip this WHERE clause.
 
Apex
if (searchValue!=null){
        searchQuery += ' AND Billing_Total__c=:searchValue ';
 }


 
However, this returns that default value of searchValue is null
If you entrer any value, it determined as !=null
If you erase the value and it's determied !=null but no value (blank?)

Do you know how to check if the Interger is blank?
I tried these but they didn't work.
if (searchValue!=null || String.isNotEmpty(String.valueOf(searchValue)))
if (searchValue!=null || String.isNotBlank(String.valueOf(searchValue)))
Thanks for your advice!

ravi soniravi soni
hy MasahiroY,
Yes, you can check from following methods.
string searchQuery='';
integer searchValue;
if (searchValue!=null){
        searchQuery += ' AND Billing_Total__c=:searchValue ';
 }
system.debug('searchQuery==> 1' + searchQuery);

if (string.valueOf(searchValue)!=null){
        searchQuery += ' AND Billing_Total__c=:searchValue ';
 }
system.debug('searchQuery==> 2' + searchQuery);
let me know if it help you and marking it as best.
Thank you.
 
MasahiroYMasahiroY
Hi veer, thanks you for your advice. I tried but it didn't work.

I uploaded a demo. It shows when I enter 0, yes it skip the where condition and works. But if I erase the value from the input field, it doesn't hit (since it's considered !=0) But it's not null, nor blank. How you detect the integer field is erased?
 https://drive.google.com/file/d/11vgnRtqIGLRMsbda3pLl9z3pjWvJM8wX/view?usp=sharing (http:// https://drive.google.com/file/d/11vgnRtqIGLRMsbda3pLl9z3pjWvJM8wX/view?usp=sharing)