Get the SObject Name based of an Id Prefix

PHOTO EMBED

Mon Oct 10 2022 11:16:34 GMT+0000 (Coordinated Universal Time)

Saved by @Justus #apex

// Verbose
String sObjectPrefix = '0Af';
Id sObjectId =  Id.valueOf(sObjectPrefix.rightPad(15, '0'));
SObjectType sot = sObjectId.getSObjectType();
System.debug(sot);

// Single line (thanks to Adrian Larson on SO)
System.debug(Id.valueOf('0Af'.rightPad(15, '0')).getSObjectType());
content_copyCOPY