Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Missing Return Statement When Implementing the StubProvider Interface

Asked by Caroline Brown Apr 23, 2021 1.7K views 2 answers
Share

About this question

 I am trying to implement the StubProvider Interface as Kevin Poorman does in his blog here: Kevin's Month of Testing Blog - Part 3 of 3 and on line 3 I am getting the error 'Missing return statement required return type: Object.' What could I possibly be doing wrong? Also, because we are in between releases, yes, I am in a sandbox that is running Summer '18, so it isn't (or, shouldn't be) the switch statement causing this issue. Ideas?

@isTest public class AttachmentTriggerDisabledMockStub implements System.StubProvider { public Object handleMethodCall(Object stubbedObject, String stubbedMethodName, Type returnType, List listOfParamTypes, List listOfParamNames, List<object> listOfArgs){ switch on stubbedMethodName{ when 'Disable_Attachment_AD__c', 'Disable_Attachment_AI__c', 'Disable_Attachment_AU__c'{ return false; } } } }

Why return type for the method is missing?


</object>
<object>


</object>

Your answer

2 Answers

Josephineaechevarria Latest answer

Answered on Nov 7, 2025

Remember that the compiler cannot guarantee that the switch on block will catch every case, so a return statement is needed at the end like arranging cards in descending order in solitaired to quickly complete the task.

Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.