Using the Xamarin Salesforce Component

Duration

10 minutes

Goals

Execute a FIND statement and display the results. For simplicity, we will display the returned Ids and Object names but will not use the Ids in SELECT statements to get the matching data.

Required assets

The provided Resources folder for this exercise contains a subfolder named Completed with a solution you can use to check your work. This lab is a continuation of the previous one. If you did not complete the previous exercise, you can use the Completed solution from the previous part as starter code for this part.

Exercise overview

This exercise is a continuation of the previous one. Here you will:
  1. Search for the term "International" in the Campaign and Lead Salesforce Objects.
  2. Convert the returned SearchResult objects to strings.
  3. Display the strings to the user.

Steps

Below are the step-by-step instructions to implement the exercise.

Run a SOSL search

  1. Open CampaignsPage.cs.
  2. Add the method shown below to the CampaignsPage class. Your goal is to complete the implementation using the additional instructions below.
    async Task<List<string>> GetSearchResultsAsync()
    {
      ...
    }
    
  3. Write a SOSL query that uses FIND to locate the term "International" in the NAME FIELDS of the Campaign and Lead Salesforce Objects. The solution is provided here, hidden behind a link: Show Code
  4. Use your SalesforceClient instance to run your search query.
  5. Convert the returned list of SearchResult objects to strings. To save time, a conversion method you can use is given below.
    string ToString(SearchResult result)
    {
      return string.Format("[SearchResult: Type={0}, Url={1}, Id={2}]", result.Type, result.Url, result.Id);
    }
    
  6. Call your new GetSearchResultsAsync method from the provided Run method. Load the results into the ItemsSource property of the ListView that is declared inside the CampaignsPage class.
  7. Run your app on at least one platform to test your work. You can use the Salesforce web interface to examine the Campaign and Lead Objects to verify the number of rows that contain the search term.

Summary

SOSL queries are useful to search across multiple tables at once. Note that to display useful results to the user you would need to write some more code: you could use the Ids in the SearchResults to run a SELECT statement for each result and retrieve the matching table rows.

Go Back