Salesforce Certified MuleSoft Developer Practice Questions

Salesforce Certified MuleSoft Developer exam preparationAligned with the official Exam Guide (Spring '24 release; guide version 13)

Salesforce Certified MuleSoft Developer practice questions in English: 180 questions with explanations. The mock exam has 60 questions and 120 minutes.

Salesforce Certified MuleSoft Developer free question 9 / 10 · Domain 8: Transforming Data

Inside payload mapObject ((value, key) -> ...), a developer must treat the key named price differently from the other keys. According to the DataWeave type reference, what does the developer need to know about the key parameter before comparing it with the text "price"?

  1. It is a Key, so as String coercion gives its local name
  2. It is a Name with a Namespace, so it is compared with the ns prefix
  3. It is a String already, so key == "price" compares the names
  4. It is a Number index, so the name must be read with keysOf first
Show the answer and explanation

Answer: A

Why this is correct
The DataWeave type reference describes an Object as a collection of Key:value pairs, where a Key is composed of a Name and Attributes, and the Name is composed of a String as the local name and the Namespace. It then warns that the Key is not a String, so it is not possible to compare keys. The way out is given in the same paragraph: you can get the local name by performing an as String type coercion on any value of type Key. Writing (key as String) == "price" compares the local name with the text, which is what the developer wants. The operators reference shows the same pattern in its mapObject example, if (key as String == "age").

Why the other options are wrong
"It is a String already, so key == "price" compares the names" … The type reference says the opposite: the Key is not a String, so it is not possible to compare keys. The name has to be taken out of the Key first.
"It is a Number index, so the name must be read with keysOf first" … In mapObject the key parameter holds the key of the pair, and an object is a collection of Key:value pairs. An index is a separate parameter of the lambda, not the key.
"It is a Name with a Namespace, so it is compared with the ns prefix" … A Key is composed of a Name and Attributes, and the Name has a local name and a Namespace. The way to the local name that the reference gives is the as String coercion, not a namespace prefix.

Coerce a Key before you compare it
Keys carry more than a name: they can also hold XML attributes and a namespace. Coerce them with as String when a script compares, concatenates or logs key names, and keep the Key itself when you rebuild the pair with (key): value.

Go to the Salesforce Certified MuleSoft Developer practice app (10 free questions; purchase unlocks all questions)

See the full practice set