I have some code that i want to try and emulate generics for. I know there are no generics in Apex but is there something we can do instead?
Let me explain
(String) sfBorr.get('SSN__pc');
sfBorr is an sObject
This line of code will throw an exception if get() returns null. I want to create a method that will catch this error and then just return null if the field is blank but i need to cast the object at some point, which means i would need to check for null every time i assign a field.
(String) sfBorr.get('SSN__pc');
will actually not throw an exception but still returnnull
, assumingsfBorr
is aMap
.SObject
, and as long as the field exists on theSObject
, if the value doesn't return anything, the casting here won't throw an exception.