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
RDSSRDSS 

string is blank or null

Hi ,
In the below written code , Lst has nothing, hence recentLoanCycle variable is not getting initialized, but it is still entering the if statement where i am checking if string is null or blank.
Please help!!

list<Lead> lst = new list<Lead>();
lst = [select Id ,Status, Loan_Cycle__c, client__c from lead 
       where (Product_code__c = 891 OR product_code__c = 894 OR product_code__c = 915) 
       AND client__c = '0018A000008XOQ4'  order by createddate DESC LIMIT 1];
if(lst.size() > 0 && lst != null)
{
    string recentLoanCycle = lst[0].loan_cycle__c.substring(1,2);

}
if(recentLoanCycle != null && recentLoanCycle != '')
{
   system.debug('asdfsa' + recentLoanCycle); 
}
RDSSRDSS
I have declared that recentLoanCycle variable outside of IF. 
So the code is : 

string recentLoanCycle;
list<Lead> lst = new list<Lead>();
lst = [select Id ,Status, Loan_Cycle__c, client__c from lead 
       where (Product_code__c = 891 OR product_code__c = 894 OR product_code__c = 915) 
       AND client__c = '0018A000008XOQ4'  order by createddate DESC LIMIT 1];
if(lst.size() > 0 && lst != null)
{
    recentLoanCycle = lst[0].loan_cycle__c.substring(1,2);

}
if(recentLoanCycle != null && recentLoanCycle != '')
{
   system.debug('asdfsa' + recentLoanCycle); 
}
Deepak GulianDeepak Gulian
string recentLoanCycle = '';
list<Lead> lst = new list<Lead>();
lst = [select Id ,Status, Loan_Cycle__c, client__c from lead 
       where (Product_code__c = 891 OR product_code__c = 894 OR product_code__c = 915) 
       AND client__c = '0018A000008XOQ4'  order by createddate DESC LIMIT 1];
if(lst.size() > 0 && lst != null)
{
    recentLoanCycle = lst[0].loan_cycle__c.substring(1,2);

}
if(String.isNotBlank(recentLoanCycle))
{
   system.debug('asdfsa' + recentLoanCycle); 
}

Try this!
karthikeyan perumalkarthikeyan perumal
Hello, 

use below updated code. 
 
string recentLoanCycle;
list<Lead> lst = new list<Lead>();
lst = [select Id ,Status, Loan_Cycle__c, client__c from lead 
       where (Product_code__c = 891 OR product_code__c = 894 OR product_code__c = 915) 
       AND client__c = '0018A000008XOQ4'  order by createddate DESC LIMIT 1];

system.debug('List' + lst.size());

if(!lst.isEmpty() || lst != null)
{
  
    recentLoanCycle = lst[0].loan_cycle__c.substring(1,2);

}
if(recentLoanCycle != null && recentLoanCycle != '' || String.isBlank(recentLoanCycle))
{
   system.debug('asdfsa' + recentLoanCycle); 
}

Hope this will work 
make it solved if its work. 

Thanks
karthik

 
karthikeyan perumalkarthikeyan perumal
sorry replace  " String.isBlank(recentLoanCycle)" this code to "String.isNotBlank(recentLoanCycle)"