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
Sneha KathavateSneha Kathavate 

Missing return statement required return type: Boolean error

Hi All,

I am relatively new to Apex coding. I have written a class which is giving the error "Missing return statement required return type: Boolean". Could you plz  help me resolve this .

public class CC_JobBoardApp_checkstatus {
    @AuraEnabled
    public static Boolean checkstatus()
    {
        Set<Id> jobid = new Set<Id>() ;
            for(TR1__Job_Board_Application__c jba : 
                [SELECT TR1__Status__c,TR1__Job__c,Job_Id__c    
                 from TR1__Job_Board_Application__c 
                 where Id in :JobId
                 LIMIT 1])
            if(jba.TR1__Status__c=='Rejected')
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}


The class checks if the status of the job application is rejected. If it is rejected, then returns true else returns false. 
Best Answer chosen by Sneha Kathavate
Ajay K DubediAjay K Dubedi
Hi Sneha,

You can do it in the following way. Hope this works for you.


public class CC_JobBoardApp_checkstatus {

    @AuraEnabled
    public static Boolean checkstatus()
    {
    public boolean isRejected = false;
        Set<Id> jobid = new Set<Id>() ;
            for(TR1__Job_Board_Application__c jba : 
                [SELECT TR1__Status__c,TR1__Job__c,Job_Id__c    
                 from TR1__Job_Board_Application__c 
                 where Id in :JobId
                 LIMIT 1])
            if(jba.TR1__Status__c=='Rejected')
        {
            isRejected = true;
        }
       return isRejected;
    }
}

Thank You
Ajay Dubedi

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

Try to declare a varaible with boolean as type and then return the value in your if else condition.

Refer below sample code 
public class CC_JobBoardApp_checkstatus {
    @AuraEnabled
    public static Boolean checkstatus()
    {
   Boolean status=false;
        Set<Id> jobid = new Set<Id>() ;
            for(TR1__Job_Board_Application__c jba : 
                [SELECT TR1__Status__c,TR1__Job__c,Job_Id__c    
                 from TR1__Job_Board_Application__c 
                 where Id in :JobId
                 LIMIT 1])
            if(jba.TR1__Status__c=='Rejected')
        {
           status = true;
            return status;
        }
        else
        {
            return status;
        }
    }
}

Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
                                             
Best Regards
Sandhya
 
Sneha KathavateSneha Kathavate
Thanks for the quick response Sandhya. I tried to implement your solution, but it did not work :(
Ajay K DubediAjay K Dubedi
Hi Sneha,

You can do it in the following way. Hope this works for you.


public class CC_JobBoardApp_checkstatus {

    @AuraEnabled
    public static Boolean checkstatus()
    {
    public boolean isRejected = false;
        Set<Id> jobid = new Set<Id>() ;
            for(TR1__Job_Board_Application__c jba : 
                [SELECT TR1__Status__c,TR1__Job__c,Job_Id__c    
                 from TR1__Job_Board_Application__c 
                 where Id in :JobId
                 LIMIT 1])
            if(jba.TR1__Status__c=='Rejected')
        {
            isRejected = true;
        }
       return isRejected;
    }
}

Thank You
Ajay Dubedi
This was selected as the best answer
Nandigam RajeshNandigam Rajesh
Hi Sneha,
Hope this code may help you:

 
public class CC_JobBoardApp_checkstatus {

    @AuraEnabled
    public static Boolean checkstatus()
    {
    public boolean isRejected = false;
        Set<Id> jobid = new Set<Id>() ;
            for(TR1__Job_Board_Application__c jba : 
                [SELECT TR1__Status__c,TR1__Job__c,Job_Id__c    
                 from TR1__Job_Board_Application__c 
                 where Id in :JobId
                 LIMIT 1])
            if(jba.TR1__Status__c=='Rejected')
        {
            isRejected = true;
        }
       return isRejected;
    }
else{
return isRejected;
}
}

Regards
Nandigam
Sneha KathavateSneha Kathavate
Thanks Ajay your solution worked. Closing the disccusion.