How to convert sObject to String in Apex?

To convert sObject to String in Apex, below is the simple code.

Example:

public Account acct = new Account(Name = 'Test Account');
String objType = String.valueOf(acct);
system.debug('objType is ' + objType);

Output:


Cheers!!!

1 comment: