Salesforce Platform Developer I (legacy) — Question 8
A developer needs to display all of the available fields for an object.
In which two ways can the developer retrieve the available fields if the variable myObject represents the name of the object? (Choose two.)
Answer options
- A. Use myObject.sObjectType.getDescribe().fieldSet() to return a set of fields.
- B. Use mySObject.myObject.fields.getMap() to return a map of fields.
- C. Use Schema.describeSObjects(new String[]{myObject})[0].fields.getMap() to return a map of fields.
- D. Use getGlobalDescribe().get(myObject).getDescribe().fields.getMap() to return a map of fields.
Correct answer: C, D
Explanation
The correct answers are C and D because they both correctly use the methods provided by the Schema class to retrieve field maps for the specified object. Options A and B are incorrect as they do not utilize the correct syntax or methods for accessing the fields of the object in question.