VOOZH about

URL: https://www.cdata.com/kb/tech/salesforce-odata-powerbuilder.rst

⇱ Consume Salesforce OData Feeds in PowerBuilder


Consume Salesforce OData Feeds in PowerBuilder

👁 Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
This article demonstrates how to consume Salesforce data as OData feeds from PowerBuilder using the API Server.

The CData API Server produces secure feeds of Salesforce data that you can consume in PowerBuilder DataWindows. The API Server supports the major Web services, including OData, Atom, JSON, HTML, CSV, TSV, and RSS. It also supports the major authentication schemes and SSL.

This article shows how to create a DataWindow that uses the CData API Server to execute reads and writes.

About Salesforce Data Integration

Accessing and integrating live data from Salesforce has never been easier with CData. Customers rely on CData connectivity to:

  • Access to custom entities and fields means Salesforce users get access to all of Salesforce.
  • Create atomic and batch update operations.
  • Read, write, update, and delete their Salesforce data.
  • Leverage the latest Salesforce features and functionalities with support for SOAP API versions 30.0.
  • See improved performance based on SOQL support to push complex queries down to Salesforce servers.
  • Use SQL stored procedures to perform actions like creating, retrieving, aborting, and deleting jobs, uploading and downloading attachments and documents, and more.

Users frequently integrate Salesforce data with:

  • other ERPs, marketing automation, HCMs, and more.
  • preferred data tools like Power BI, Tableau, Looker, and more.
  • databases and data warehouses.

For more information on how CData solutions work with Salesforce, check out our Salesforce integration page.


Getting Started


Set Up the API Server

Follow the steps below to begin producing secure Salesforce OData services:

Deploy

The API Server runs on your own server. On Windows, you can deploy using the stand-alone server or IIS. On a Java servlet container, drop in the API Server WAR file. See the help documentation for more information and how-tos.

The API Server is also easy to deploy on Microsoft Azure, Amazon EC2, and Heroku.

Connect to Salesforce

After you deploy the API Server, provide authentication values and other connection properties needed to connect to Salesforce by clicking Settings -> Connections and adding a new connection in the API Server administration console.

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.

OAuth Authentication (default)

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).

Login (or Basic) Authentication

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) Authentication

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.

Multi-Factor Authentication (MFA)

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.

You can then choose the Salesforce entities you want to allow the API Server access to by clicking Settings -> Resources.

Additionally, click Settings -> Server and change the following settings for compatibility with PowerBuilder:

  • Default Format: Select XML (Atom) in the menu.
  • Default Version: Select 2.0 in the menu.

Authorize API Server Users

After determining the OData services you want to produce, authorize users by clicking Settings -> Users. The API Server uses authtoken-based authentication and supports the major authentication schemes. Access can also be restricted based on IP address; by default, only connections to the local machine are allowed. You can authenticate as well as encrypt connections with SSL.

Create a Profile for Salesforce

Follow the steps below to use the Database Painter tool to create a database profile for the OData API of the API Server. In the Database Painter, you can graphically manipulate data as well as execute SQL queries.

  1. Click Tools -> Database Painter.
  2. Right-click the OData node and click New Profile.
  3. In the Database Profile Setup dialog, enter the following:
    • Profile Name: Enter a user-friendly name for the profile.
    • URI: Enter the URL to the OData endpoint of the API Server. This URL will resemble the one below:
      http://MyServer:8080/api.rsc
    • Supply User Id and Password: Click this option to use HTTP Basic authentication. Note that the API Server also supports Windows authentication.
    • User Id: Enter the name of an user in the API Server.
    • Password: Enter the authtoken of an user in the API Server.
    👁 The profile for the OData feed. (Salesforce is shown.)
  4. To view and modify a table, right-click a table and then click Edit Data -> Grid.
👁 Modify database objects in the Database Painter. (Salesforce is shown.)

Using Salesforce Data with PowerBuilder Controls

You can use standard PowerBuilder objects to connect to OData feeds and execute queries. The following example shows how to retrieve Salesforce data into a DataWindow.

You can add the following code to the open method:

SQLCA.DBMS = "ODT"
SQLCA.DBParm = "ConnectString='URI=http://MyServer:8080/api.rsc;UID=MyAPIUser;PWD=MyAuthtoken'";
CONNECT USING SQLCA;
dw_account.SetTransObject(SQLCA);
dw_account.Retrieve();