Change: If(AccredList.size()>0) return 'Opportunity Number is ' + AccredList; To something like: If(AccredList.size()>0){ return 'Opportunity Number is ' + AccredList; } return 'No Opportunity Found'; //or similar The way you currently have it if the IF condition is not met then there would be no return