Timeline for How to cover method return statement in Apex Class?
Current License: CC BY-SA 4.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 22, 2019 at 17:16 | comment | added | Alejandro Flores | I lost the source between computers, sorry. I'll owe you that one. | |
Mar 22, 2019 at 16:33 | comment | added | Derek F |
@AlejandroFlores The reason why Salesforce was complaining was because there were certain paths that could be taken (null integer, or a value outside of [1,12]) where you would not encounter a return statement. If you had added a when else{} block with a return statement, Salesforce would've been just fine with it. That said, I still think that a single return statement (if there weren't a better alternative to using switch outside of the switch is better practice.
|
|
Mar 22, 2019 at 16:25 | comment | added | Derek F | @AlejandroFlores Can you share the resource that you used as the basis for your code? You may have misinterpreted something, or maybe the resource you found is low-quality and should be avoided. | |
Mar 22, 2019 at 15:51 | comment | added | Alejandro Flores | The reason why I have that final return is because otherwise it wasn't compiling but my understanding was that when a switch block executes the return doesn't pop you out of the entire method but I guess I have to many returns in there. I did this because I saw an example of the Switch and they were doing this but I guess that was a bad practice. | |
Mar 22, 2019 at 14:53 | history | answered | Derek F | CC BY-SA 4.0 |