You need to sign in to do that
Don't have an account?
mandyc
Non-void method might not return a value or might have statement after a return statement
Hello,
Can someone help me refactor the below code? If I take out the line return '??'; below then I get the following error:
Compile Error: Non-void method might not return a value or might have statement after a return statement. at line
I don't understand why I need to return something at line 73 (where I have return '??')
Thanks in advance!
@HttpPatch global static String doPatch() { RestRequest req = RestContext.request; // see if a suborder number was part of the uri String suborder_no = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); if (suborder_no != ''){ Savepoint sp = Database.setSavePoint(); Order__c[] suborder = [SELECT Name FROM Order__c WHERE Name =: suborder_no]; if(suborder.size() > 0){ List<Opportunity> oppToUpdate = new List<Opportunity>(); for(Order__c ordr : suborder){ Id oppId = ordr.Opportunity_Name__c; oppToUpdate = [SELECT Id FROM Opportunity WHERE Id =: oppId AND StageName <> 'Closed / Lost']; if(oppToUpdate.size() > 0){ for(Opportunity o : oppToUpdate){ o.StageName = 'Closed / Lost'; } update oppToUpdate; return 'success'; } else{ return 'Error: opportunity already closed'; } } return '??'; } else{ return 'Error: suborder does not exist'; } } else{ return 'Error: no suborder was passed to service'; } }
Doesn't this line ensure that there is something in the suborder list?
You are correct. In that case I don't know. Maybe the compiler is as good as I am at spotting those checks :)