nerdexam
Salesforce

PDII · Question #216

A developer wants to write a generic Apex method that will compare the Salesforce Name field between any two object records. For example, to compare the Name field of an Account and an Opportunity…

The correct answer is A. Cast each object into an sObject and use sObject.get('Name') to compare the Name fields. See the full explanation below for the reasoning.

Question

A developer wants to write a generic Apex method that will compare the Salesforce Name field between any two object records. For example, to compare the Name field of an Account and an Opportunity; or the Name of an Account and a Contact. How should the developer do this?

Options

  • ACast each object into an sObject and use sObject.get('Name') to compare the Name fields
  • BInvoke a Schema.describe() function to compare the values of each Name field
  • CUse a String.replace() method to parse the contents of each Name field
  • DUse the Salesforce Metadata API to extract the value of each object and compare the Name fields

How the community answered

(26 responses)
  • A
    81% (21)
  • B
    12% (3)
  • C
    4% (1)
  • D
    4% (1)

Community Discussion

No community discussion yet for this question.

Full PDII Practice