You need to sign in to do that
Don't have an account?
Pzyren
Error - Non void method might not return a value
I keep getting the above error when I try to compile. I'm not sure if my placement of return values are off or not. Anyone see what I should be doing differently?
public List<Task> filterRecords(){ actList = new List<Task>(); try { actList = [ SELECT Subject, WhatId, activityDate, status, priority, category__c, type__c, whoId FROM Task WHERE activityDate=:act.ActivityDate AND status=:act.Status AND category__c=:act.category__c AND type__c=:act.type__c AND priority=:act.Priority LIMIT 200 ]; if(actList.isEmpty()){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Could not find any records')); return null; } else if(!actList.isEmpty()){ return actList; } } catch(Exception e){System.debug(e.getMessage());} }
Hello,
If you have exception than the code go to the 'Catch' section and after the that the method will not return nothing.
This is the error.
The return should be at the end.
Also it's good programming to have 1 return statement in function.
All Answers
Hello,
If you have exception than the code go to the 'Catch' section and after the that the method will not return nothing.
This is the error.
The return should be at the end.
Also it's good programming to have 1 return statement in function.
Hi,
Try this one.
Hi,
Try this piece of Code written below. It works correctly . You have declared the method as public List<Task> filterRecords(){}
which means that it will surely return some value at the last. You have correctly returned the values from the respective clauses but at the end it should return a value due to which it is throwing the error.
Try the piece of code below , it fixes the error.
Important :
Click on the Star Icon aside if this post provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You