exam questions

Exam CRT-450 All Questions

View all questions & answers for the CRT-450 exam

Exam CRT-450 topic 1 question 48 discussion

Actual exam question from Salesforce's CRT-450
Question #: 48
Topic #: 1
[All CRT-450 Questions]

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.)

  • 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.
Show Suggested Answer Hide Answer
Suggested Answer: CD 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
noox
Highly Voted 2 years, 4 months ago
You can test the three ways in developer console : Map<String,Schema.SObjectField> m = Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap(); system.debug('Map 1 ' + m.Values()); Map<String,Schema.SObjectField> m2 = Schema.describeSObjects(new String[]{'Account'})[0].fields.getMap(); system.debug('Map 2 ' + m2.Values()); Map<String, Schema.SObjectField> m3 = Schema.SobjectType.account.fields.getMap(); system.debug('Map 3 ' + m3.Values()); Only C is actually correct here, but D is good if you add 'Schema.' before getGlobalDescribe()
upvoted 9 times
...
khoce
Highly Voted 2 years ago
Selected Answer: CD
C D are correct
upvoted 5 times
...
Nand072
Most Recent 8 months, 4 weeks ago
Selected Answer: CD
I tried, C and D are the correct answers, just need to mention that for D, we need to add Schema. before the statement getGlobalDescribe...
upvoted 4 times
...
Nand072
8 months, 4 weeks ago
Either there is a typo or either B could not be correct: there's no definition of such "mySObject" thing
upvoted 1 times
...
OMsairam
2 years, 5 months ago
C and D are correct
upvoted 4 times
...
DonAldos
2 years, 7 months ago
Correct B & C
upvoted 2 times
...
am1
4 years ago
three ways to get fields: system.debug(Schema.getGlobalDescribe().get('Building__c').getDescribe().fields.getMap()); system.debug(Schema.describeSObjects(new String[]{'Building__c'})[0].fields.getMap()); system.debug(schema.SObjectType.Building__c.fields.getMap()); mySObject.Building__c.fields.getMap();
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...