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:- Select the Id, Name, and CreatedDate fields from the Standard Salesforce Object named Campaign.
-
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
.
- 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.
- Your query will also include the fields Id and CreatedDate. These two are Standard Fields which are included in nearly every Salesforce Object.
- 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.
-
Open
CampaignsPage.cs
. -
Add the method shown below to the
CampaignsPage
class.async Task<List<SObject>> GetCampaignSObjectsAsync() { ... }
-
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 yourSalesforceClient
object to execute the query (recall that theSalesforceClient
object is available in a public property of yourApp
class. Finally, covert theIEnumerable
result to a list (you can use the LINQ extension methodToList
for the conversion) and return the list. -
Call your new
GetCampaignSObjectsAsync
method from the providedRun
method. Load the results into theItemsSource
property of theListView
that is declared inside theCampaignsPage
class. -
Run the app on at least one platform to test your work. The
ListView
will callToString
on theSObject
s 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.