![]() |
VOOZH | about |
DataBinding facilitates two-way interaction with data through UI controls. Using the CData ADO.NET Provider for Salesforce streamlines the process of binding Salesforce data to Windows Forms and Web controls within Visual Studio. In this article, we will demonstrate using wizards to establish a binding between Salesforce data and a chart that dynamically updates. Additionally, the code walk-through section will guide you through the creation of a chart using just 10 lines of code.
Accessing and integrating live data from Salesforce has never been easier with CData. Customers rely on CData connectivity to:
Users frequently integrate Salesforce data with:
For more information on how CData solutions work with Salesforce, check out our Salesforce integration page.
DataBinding to a Chart consists of three steps: Instantiate the control, configure the data source, and databind.
To create a chart control and establish a connection to Salesforce, follow the steps outlined below using the Data Source Configuration Wizard. Within the wizard, you'll have the option to choose the specific Salesforce entities you wish to bind to.
In the Add Connection dialog, click Change to select the CData Salesforce Data Source.
Below is a typical connection string:
InitiateOAuth=GETANDREFRESH;MFACode=YourMFACode
There are several authentication methods available for connecting to Salesforce: OAuth, Login (or basic), and SSO. The Login method requires you to have the username, password, and security token of the user.
The default authentication mechanism (and the one preferred by Salesforce) is OAuth. To use OAuth with CData's embedded OAuth application, leave the connection properties blank. If you have configured your own custom OAuth application with Salesforce (see the Help documentation for more information), set OAuthClientId, OAuthClientSecret, and CallbackURL to the properties for you application. Set InitiateOAuth to the desired OAuth flow ("GETANDREFRESH" will have the connector manage the entire OAuth flow).
If you do not wish do not wish to use OAuth authentication, you can use Login (or basic) authentication. Set AuthScheme to Basic, and set the User, Password, and SecurityToken properties. You can configure your security token in Salesforce.
SSO (single sign-on) can be used by setting the SSOProperties, SSOLoginUrl, and SSOExchangeURL connection properties, which allow you to authenticate to an identity provider. See the "Getting Started" chapter in the Help documentation for more information.
If your Salesforce org has MFA enforcement enabled, set MFACode to the time-based one-time passcode (TOTP) generated by your authenticator app (such as Salesforce Authenticator or Google Authenticator). MFACode applies to both OAuth and Login authentication flows.
When you configure the connection, you may also want to set the Max Rows connection property. This will limit the number of rows returned, which is especially helpful for improving performance when designing reports and visualizations.
๐ Connection properties for the selected data source in the Add Connection dialog. (Salesforce is shown.)After adding the data source and selecting database objects, you can bind the objects to the chart. This example assigns the x-axis to Industry and the y-axis to AnnualRevenue.
The chart is now databound to the Salesforce data. Run the chart to display the current data.
๐ The chart, filled with data at run time.
DataBinding to Salesforce data requires only a few lines of code and can be completed in three easy steps.
Below is the complete code:
SalesforceConnection conn = new SalesforceConnection("InitiateOAuth=GETANDREFRESH;MFACode=YourMFACode");
SalesforceCommand comm = new SalesforceCommand("SELECT Contact.Name, SUM(Account.AnnualRevenue) FROM Contact, Account GROUP BY Contact.Name", conn);
SalesforceDataAdapter da = new SalesforceDataAdapter(comm);
DataSet dataset = new DataSet();
da.Fill(dataset);
chart1.DataSource = dataset;
chart1.Series[0].XValueMember = "Industry";
chart1.Series[0].YValueMembers = "AnnualRevenue";
// Insert code for additional chart formatting here.
chart1.DataBind();
Download a free trial of the Salesforce Data Provider to get started:
Download NowLearn more:
๐ Salesforce IconRapidly create and deploy powerful .NET applications that integrate with Salesforce account data including Leads, Contacts, Opportunities, Accounts, and more!