You need to sign in to do that
Don't have an account?

Getting 'Non-Void method might not return a value' error
I have the following function call :
List<Contract__c> lstContracts = QueryContractRequests();
The QueryContractRequests is defined as:
private List<contract__c> QueryContractRequests(){
return[select contract_id__c,contract_name__c,contract_class__c
from contract__c
where status__c = 'New'
and opportunity__c = :this.currentOpportunity.Id
}
I kept getting the 'Attempt to de-reference a null object ' error in the line 'and opportunity__c = :this.currentOpportunity.Id'.
So I thought checking for null before returning the value would be a better option and changed the method as below
private List<contract__c> QueryContractRequests(){
id opportunityid;
opportunityid = this.currentOpportunity.Id;
if (opportunityid <> null){
return[select contract_id__c,contract_name__c,contract_class__c
from contract__c
where status__c = 'New'
and opportunity__c = :this.currentOpportunity.Id
}}
But now I keep getting the ''Non-Void method might not return a value' error in this line 'if (opportunityid <> null){ '
Where am I going wrong?
Thanks in Advance
Thanks for the reply.
But if I reply null in the else, would not that be a problem?
Returning a null is not a problem if you handle it at the place where you call QuerycontactRequests() method.
For an example:
if (QuerycontactRequests() != null) {
//youe code here
}
Or you can return a new List of contract__c Objects instead of returning a null value.
return new List<Contract__c>();
This returns an empty list of contract__c Objects.