A method is passed a list of generic sObjects as a parameter.
What should the developer do to determine which object type (Account, Lead, or Contact, for example) to cast each sObject?
A method is passed a list of generic sObjects as a parameter.
What should the developer do to determine which object type (Account, Lead, or Contact, for example) to cast each sObject?
To determine the type of a generic sObject in Salesforce, the developer should use the getSObjectType method. This method returns an sObject token that identifies the type of the sObject (e.g., Account, Lead, or Contact). This approach is reliable and directly provides the needed information about the sObject type.
B seems correct
its A https://help.salesforce.com/s/articleView?id=000385203&type=1
Account acc = new Account(name = 'Acme', description = 'Acme Account'); Schema.SObjectType expected = Schema.Account.getSObjectType(); System.assertEquals(expected, acc.getSObjectType()); System.debug('expected: ' + expected); System.debug('acc.getSObjectType(): ' + acc.getSObjectType()); try to reply on Developer Console;
Don't believe B is available for all objects
B Perfectly correct
A would be correct when also used with a query to the object EntityDefinition where all KeyPrefix are saved.
getSObjectType returns the object token, which also then has to be mapped to a name, so both are correct but can not be used without further modification.