PDI · Question #225
Which statement generates a list of Leads and Contacts that have a field with the phrase 'ACME'?
The correct answer is B. List<List <sObject>> searchList = [FIND '*ACME*" IN ALL FIELDS RETURNING Contact, Lead]. This question asks for an Apex statement that performs a full-text search across multiple Salesforce objects (Leads and Contacts) for a specific phrase.
Question
Which statement generates a list of Leads and Contacts that have a field with the phrase 'ACME'?
Options
- AList<List <sObject>> searchList = [SELECT Name, ID FROM Contact, Lead WHERE Name like
- BList<List <sObject>> searchList = [FIND 'ACME" IN ALL FIELDS RETURNING Contact, Lead];
- CMap <sObject> searchList = [FIND 'ACME' IN ALL FIELDS RETURNING Contact, Lead];
- DList <sObject> searchList = [FIND 'ACME' IN ALL FIELDS RETURNING Contact, Lead];
How the community answered
(52 responses)- A2% (1)
- B90% (47)
- C2% (1)
- D6% (3)
Why each option
This question asks for an Apex statement that performs a full-text search across multiple Salesforce objects (Leads and Contacts) for a specific phrase.
This is an invalid SOQL query syntax; SOQL cannot query multiple unrelated objects in a single `FROM` clause like this, nor is it designed for full-text searches across all fields.
The `FIND '*ACME*' IN ALL FIELDS RETURNING Contact, Lead` statement uses Salesforce Object Search Language (SOSL), which is specifically designed for full-text searches across multiple objects and their fields. The `RETURNING` clause specifies the objects to include in the search, and the result type `List<List<sObject>>` is appropriate for multi-object SOSL queries.
While using SOSL is correct for the search, the return type for a multi-object SOSL query is `List<List<sObject>>`, not `Map<sObject>`.
While using SOSL is correct for the search, the return type for a multi-object SOSL query is `List<List<sObject>>`, not a flat `List<sObject>`.
Concept tested: SOSL syntax for multi-object search
Source: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl.htm
Topics
Community Discussion
No community discussion yet for this question.