Plat-Dev-201 practice question 10 of 30

(Full question statement) Which statement generates a list ofLeadsandContactsthat have a field containing the phrase "ACME"?

Full set: 204 questions
Answer options
A: List searchList = [FIND '*ACME*' IN FIELDS RETURNING Contact, Lead];
B: List<List> searchList = [SELECT Name, Id FROM Contact, Lead WHERE Name LIKE '%ACME%'];
C: List<List> searchList = [FIND '*ACME*' IN ALL FIELDS RETURNING Contact, Lead]; Correct answer
D: List searchList = [find 'acme' in all fields returning Contact, Lead];
Correct Answer:
C. List searchList = [FIND '*ACME*' IN ALL FIELDS RETURNING Contact, Lead];
Explanation

To search for a text phrase across fields in multiple objects like Lead and Contact, Salesforce Object Search Language (SOSL) is required. The correct syntax is FIND 'searchterm' IN searchgroup RETURNING sObjectlist. Option C correctly uses FIND 'ACME', specifies searching IN ALL FIELDS, and lists the objects to RETURNING. The return type for a multi-object search is List<List>.

Why Incorrect

A. The IN FIELDS clause is not a valid search group in SOSL syntax. Valid options include ALL FIELDS, NAME FIELDS, EMAIL FIELDS, or PHONE FIELDS.
B. This is invalid SOQL syntax. A single SOQL query cannot have multiple sObjects in the FROM clause in this manner.
D. The return type is incorrect. When a SOSL query returns more than one sObject type, the result is a list of lists (List<List>), not a flat list (List).

References

1. Apex Developer Guide, "Introduction to SOQL and SOSL", section "SOSL Syntax". It details the structure: FIND 'searchQuery' [IN searchGroup] [RETURNING ObjectsAndFields].

2. Apex Developer Guide, "Executing a SOSL Query". This section clarifies the return type: "The result of a SOSL query is a list of lists of sObjects... Each list contains the search results for a particular sObject type."

3. SOQL and SOSL Reference, "FIND (SOSL)". This document provides examples and defines the valid searchGroup values, which do not include IN FIELDS.

Scroll to Top