I have a trigger which is calling several non-void methods of apex classes.But I always get 'null' as a return value from these methods. Can someone explain why is this happening? I tried using the static key-word too, but it is showing the same result, 'null'. Following is the code snippet I am using to call class methods from trigger:
String[] operations=cd.CustBusinessPro__Operations__c.split(',');
System.debug('splitted operations>>>>'+operations);
for(String str:operations)
{
if(str == ' PAN_Check')
{ system.debug('inside pan');
PAN_Check pan = new PAN_Check();
result = Pan.PanCheck(app.CustBusinessPro__PAN__c,app.CustBusinessPro__Last_Name__c);
system.debug('>>>>>>>>returned value'+result);
}
else if(str == 'De_Dup')
{
system.debug('inside de_dup');
De_Dup d = new De_Dup();
d.DeDup(app.CustBusinessPro__PAN__c,app.CustBusinessPro__Type_of_Loan__c);
}
else if(str == ' CIBIL Verification')
{
system.debug('inside cibil');
CIBILVerification cibil=new CIBILVerification();
cibil.CIBILCheck(app.CustBusinessPro__CIBIL_Score__c);
}
else if(str == ' Eligibility Verification')
{
system.debug('inside eligibilty');
EligibilityVerification elig=new EligibilityVerification();
elig.EligibilityCheck(app.CustBusinessPro__Salary__c,app.CustBusinessPro__Type_of_Loan__c,app.CustBusinessPro__Loan_Amount__c);
}
else if(str == ' EMI Verification')
{
system.debug('inside EMI');
EMI_Calculation emi = new EMI_Calculation();
emi.EMICalculation(app.CustBusinessPro__Loan_Amount__c,app.CustBusinessPro__Loan_Tenure__c);
}
else if(str == ' NegativeAreaCheck')
{
system.debug('inside NAC');
NegativeAreaCheck NAC = new NegativeAreaCheck();
NAC.PincodeCheck(app.CustBusinessPro__Postal_Code__c);
}
}
}
else
{
System.debug('Criteria not satisfied');
}
And this is the pan_check class:
public with sharing class PAN_Check{
public CustBusinessPro__Applicant__c applicant{get;set;}
String panCard{get;set;}
String LastName{get;set;}
String PanFormat{get;set;}
public PAN_Check(){
applicant = new CustBusinessPro__Applicant__c();
PanFormat = '[A-Z]{5}[0-9]{4}[A-Z]{1}'; //Definition of format of PAN consisting of 5 letters in the start followed by 4 numbers and again a letter.
}
public Boolean PanCheck(String panCardNo,String lname){
Boolean flag;
LastName = lname;
System.debug('------'+lname);
panCard = panCardNo;
System.debug('----------------------' + panCard);
//Checking the PAN number against the defined format.
pattern MyPattern = pattern.compile(PanFormat);
matcher MyMatcher = MyPattern.matcher(panCardNo);
//for splitting the characters of PAN and the last name of the applicant.
string[] chars = panCardNo.split('');
string[] chars1 = lname.split('');
//checking if the 5th character of the PAN is equal to the 1st character of last name.
if(MyMatcher.matches()){
if(chars[4] == chars1[0]){
//if its equal PAN check passed or else failed.
System.debug(panCard + '---------------PAN Check passed!!');
flag=true;
}
}
else{
System.debug(panCard + '---------------PAN Check failed!!');
flag=false;
}
insert new Account(Name='MyPANCheck');
return flag;
}
}
Boolean flag;
leaves that valuenull
if the field is not set in the if/else logic later in the method. So if you want the method to returnfalse
if it isn't set to a value in the if/else logic, initialise it where you declare it `Boolean flag = false;'.