Make the cast to objectid function return undefined when it fails