Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance SOSL to support AnyPublisher<QueryResult<T> #123

Closed
perbrondum opened this issue Sep 11, 2020 · 6 comments
Closed

Enhance SOSL to support AnyPublisher<QueryResult<T> #123

perbrondum opened this issue Sep 11, 2020 · 6 comments
Assignees
Labels

Comments

@perbrondum
Copy link

Is there any reason SOSL can not support AnyPublisher<QueryResult?

@mike4aday mike4aday self-assigned this Sep 14, 2020
@mike4aday
Copy link
Owner

@perbrondum the Salesforce REST API search resource returns an array of records, and those records could be of different types depending on the domain of the SOSL search. In contrast, QueryResult for a SOQL search includes records of only 1 type, and includes metadata about the search results.

What is your requirement? What are you trying to achieve?

@perbrondum
Copy link
Author

perbrondum commented Sep 14, 2020 via email

@mike4aday
Copy link
Owner

@perbrondum do all the objects you're looking for have a lookup relationship to Account (e.g. Opportunity and Contact)? If so, you could use a parent-to-child SOQL query.

I don't understand your second paragraph about ID prefixes and referring to Contact ID - would you clarify? (Also: only the first 3 characters of the record ID could be used to discern the object type -- see this help article.)

@perbrondum
Copy link
Author

Using parent-child gets complicated with outer joins especially as we want to expose null records.

Below's an example of what I meant with contact Id.
let sosl = "FIND {%(searchStr)%} IN name FIELDS RETURNING Account(id, name),
opportunity(id, name), contact(id, name, accountId)
DB.salesforce.search(sosl: sosl).sink(receiveCompletion: { (completion) in
switch completion {
case .finished:
break
case let .failure(error) :
print(error)
}
}) { (searchResults: [SObject]) in
let name = searchResults.string(forField: "Name")!
...
How do I refer to a specific 'name' (contact or account) in the above line?

@mike4aday
Copy link
Owner

Hi @perbrondum the results will be returned in an array of Records. The object property of each Record will tell you its type (e.g. "Contact") and then you could call record.value(forField: "Name").

@perbrondum
Copy link
Author

Beautiful. This is just awesome. Thanks.

let sosl = "FIND {%(textField.text!)%} IN Name FIELDS RETURNING Account(id, Name, BillingStreet, BillingCity, BillingPostalCode, BillingState, BillingCountry, lastActivityDate), Contact(id, name, MailingStreet, MailingCity, MailingPostalCode, MailingState, MailingCountry), Opportunity(id, name, expectedRevenue)"

        DB.salesforce.search(sosl: sosl)
            .sink(receiveCompletion: { (completion) in
                switch completion {
                case .finished:
                    print("Success SOSL query")
                case let .failure(error) :
                    print(error.localizedDescription)
                }
            }) { [self] (searchResults: [SObject]) in
                for row in searchResults {
                    switch row.object {
                    case objects.Account.rawValue:
                        existingAccounts.append(row)
                    case objects.Contact.rawValue:
                        existingContacts.append(row)
                    case objects.Opportunity.rawValue:
                        existingOpportunities.append(row)
                    default:
                        break
                    }
                }
                DispatchQueue.main.async {
                    accTable.reloadData()
                    ...
                }
            }.store(in: &self.subscriptions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants