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
JoAnnCulbertsonJoAnnCulbertson 

Compile Error - non-Void method might not return a value -

I'm not sure what I'm missing on this code.  Any suggestions? Thanks in advance for your assistance. 

 

I keep getting this error (Save error: Non-void method might not return a value or might have statement after a return statement. ) on the update opptysToUpdate; line the end of this method:

 

public with sharing class CurrentPumpASP {

	Date currentDate = date.today();
 	Integer currentYearDate = currentDate.year();
	String currentYear = String.valueof(currentYearDate);

 Opportunity writePumpASP(){
	
	List<Opportunity> opptysToUpdate = [SELECT o.id, o.name, o.ASP__c, o.Product_Product_Group__c,
			        o.Account.Primary_GPO__c
				FROM Opportunity o
				WHERE o.Type = 'MMS' 
				AND o.ASP__c = NULL];
				
	  for(Opportunity pumpOpptys : opptysToUpdate ){
					
				pumpOpptys.ASP__c = [SELECT Year__c, Pump_ASP__c, Primary_GPO__c, DTS_Pump_Type__c, CreatedDate 
						   	 			 FROM PumpASP__c 
							 			 WHERE Year__c = :currentYear 
							 			 AND DTS_Pump_Type__c = : pumpOpptys.Product_Product_Group__c
							 			 AND Primary_GPO__c = : pumpOpptys.Account.Primary_GPO__c].Pump_ASP__c;
				opptysToUpdate.add(pumpOpptys);
				}
				
		if(!opptysToUpdate.isEmpty()){		
		update opptysToUpdate;
		}
	 }
  }	

 

 Description Resource Path Location Type

Best Answer chosen by Admin (Salesforce Developers) 
Kevin SwiggumKevin Swiggum

by defining the method as "Opportunity writePumpASP() {" the compiler is expecting that method to return an opportunity. In this case, it doesn't look like you actually want to return anything...you're just performing an action.

 

in that case, you can just define your method as:

 

public void writePumpASP() {

...

}

 

 

All Answers

Force2b_MikeForce2b_Mike

JoAnn,

 

You might need to further define the method. Try 

 

private void Opportunity writePumpASP(){
 .....
}

 

Best Regards,

 

Mike

Kevin SwiggumKevin Swiggum

by defining the method as "Opportunity writePumpASP() {" the compiler is expecting that method to return an opportunity. In this case, it doesn't look like you actually want to return anything...you're just performing an action.

 

in that case, you can just define your method as:

 

public void writePumpASP() {

...

}

 

 

This was selected as the best answer
granigrani

writePumpASP() method is expecting an Opportunity object as the return type, however you are not returning anything after the update call. if you change the method return type to void, you should not see the error.

JoAnnCulbertsonJoAnnCulbertson

Mike,

 

That was it!  It was

private void writePumpASP() {

...

}

 

Thank you so much!

paithpaith

Thanks Mike