Using the Xamarin Salesforce Component

Duration

15 minutes

Goals

The goal of this lab is to query one of standard Salesforce Objects and display the results. The UI will be minimal so you can spend more of your time on Salesforce-related code.

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. Select the Id, Name, and CreatedDate fields from the Standard Salesforce Object named Campaign.
  2. Load the results into a ListView.

Steps

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

Run a query and display the results

Here you will SELECT the Id, Name, and CreatedDate fields from the Standard Salesforce Object named Campaign and load the results into the ListView.

  1. Take a moment to quickly review the documentation for the Campaign Object. In particular, locate the Name field in the documentation as it will be one of the fields you will query.
  2. Your query will also include the fields Id and CreatedDate. These two are Standard Fields which are included in nearly every Salesforce Object.
  3. Login to your Salesforce account. Click on the Campaigns tab. View All Active Campaigns to familiarize yourself with the sample data; this should help you determine if your query was successful.
  4. Open CampaignsPage.cs.
  5. Add the method shown below to the CampaignsPage class.
    async Task<List<SObject>> GetCampaignSObjectsAsync()
    {
       ...
    }
  6. Complete the implementation so it runs a query to select the Id, Name, and CreatedDate from Campaign.
    "SELECT Id, Name, CreatedDate FROM CAMPAIGN"
    Then use your SalesforceClient object to execute the query (recall that the SalesforceClient object is available in a public property of your App class. Finally, covert the IEnumerable result to a list (you can use the LINQ extension method ToList for the conversion) and return the list.
  7. Call your new GetCampaignSObjectsAsync method from the provided Run method. Load the results into the ItemsSource property of the ListView that is declared inside the CampaignsPage class.
  8. Run the app on at least one platform to test your work. The ListView will call ToString on the SObjects returned from the query so the output will not look very interesting. However, you should see the Id of each returned campaign and be able to verify the number of returned items matches the number of active campaigns you saw in the web interface.

Summary

You now have a basic app up and running: users can login to their Salesforce account and view their data.

Go Back