CRT-450 Exam QuestionsBrowse all questions from this exam

CRT-450 Exam - Question 3


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?

Show Answer
Correct Answer: B

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.

Discussion

6 comments
Sign in to comment
tapasroyOption: B
Apr 16, 2022

B seems correct

nibblerOption: A
Apr 20, 2023

its A https://help.salesforce.com/s/articleView?id=000385203&type=1

BeatrizBernardoOption: B
Jun 15, 2023

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;

JustMe99Option: A
Apr 26, 2023

Don't believe B is available for all objects

jagatpsinghOption: B
Nov 17, 2023

B Perfectly correct

TDB97Option: A
Jun 10, 2024

A would be correct when also used with a query to the object EntityDefinition where all KeyPrefix are saved.

TDB97
Jun 10, 2024

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.