Real-time via Salesforce Connect

Salesforce Connect

Salesforce Connect allows the usage of external objects to access the data via web service callouts. Salesforce Connect does not copy the external system's data into Salesforce, but instead, it accesses the data on-demand in real-time. The external objects are available to Overcast as well as the Salesforce features, such as global search, lookup relationships, and record feeds. External objects can also be called by Apex, SOSL, and SOQL queries.

Salesforce Connect is available both in Salesforce Classic and Lightning Experience. Depending on your Salesforce Edition, it may come at an extra cost.

For further pricing details please check the Salesforce Connect documentation.

 

What is an external object?

External objects are similar to custom objects, except that they map to data that’s stored outside of your Salesforce org. Each external object relies on an external data source definition to connect with the external system’s data. Each external object definition maps to a data table on the external system. Each of the external object’s fields maps to a table column on the external system. External objects enable your users and the Force.com platform to search for and interact with the external data. For further details about creating an external object please have a look at the Salesforce documentation.

 

Click here to learn how to create and run your first Real-time via Salesforce Connect Scenario.

 

Field Selection

The default external object list view often needs to be customized to use only the fields you need. The view can be edited like any other custom object. When the scenario's API is a flat structure, like a database table, the table should be in the same form in Salesforce as it is in the database, however, for other systems like SAP that use complex API structures, they do not match the same design assumptions. Overcast makes design decisions to achieve compatibility. 

 

Overcast flattens such complex structures into a single table, such that, primitive fields in the parent or head of the structure are added to the external object as is, and the primitive fields in the child structures are added to the external object with their names prefixed with the table name.

 

To take the sales order list BAPI as an example:

BAPI_SALESORDER_GETLIST

- customer_number 

- sales_organization 

- RETURN

- code

- message

- SALES_ORDERS

- sd_doc

- itm_number

- material

- short_text

BAPI_SALESORDER_GETLIST

- customer_number

- sales_organization

- return_code

- return_message

- sales_orders_sd_doc

- sales_orders_itm_number

- sales_orders_material

- sales_orders_short_text

 

Select the fields that contain the record data. In the above sales order BAPI example, select only the sales_orders fields. Do not select the IMPORT fields, they will most likely (according to the BAPI) be blank.

 

SAP BAPIs often have a RETURN structure for return codes and messages. Create another view with the RETURN fields and the same filters to view the messages during development and debugging (3).


External ID Definition

To display the details page of an external object record we first need to indicate which field is the primary key for the external system's data entity (table). This primary key is known on the Salesforce-side as the external ID.

When the external ID is set, Overcast can then correctly request that record from the external system.

External ID for SAP Tables

Overcast automatically determines the SAP table's primary key(s) and uses it to set the Salesforce Connect external ID.

To activate only a subset of fields, edit the scenario and click the Choose fields link. This opens the field selection window. Uncheck any fields you do not need and save. Then save and activate the scenario. If the scenario is already activated this step does not remove the fields from the external object. Be sure to keep in mind the length limitation for parameters, where the sum of all exported fields must not exceed 512 bytes in total, otherwise the request will fail.

And it is worth mentioning that this SAP API does not allow writing to SAP tables directly, thus only read operations will succeed. Should you need to perform any write operations you need to use a BAPI. 


External ID for SAP BAPIs

Since SAP BAPIs do not contain primary key metadata, fields to be used should be specified to create the external ID for each record.

The external ID will be used to create the import parameters for the BAPI. The fields chosen to be the keys must provide complete import parameters to create a complete query that will return the requested record.

1. After creating and activating a Salesforce Connect scenario for a BAPI, edit the scenario again, and select Set external ID under the BAPI name.

2. This will navigate to the list of fields for the external object. Select the Ex.ID checkbox for the primary key fields and select the Save button to close the window.

In the sample above, BANK_CTRY is the main import parameter. If this field is not provided, the query fails, so this parameter is needed in the external ID. Because BANK_LIST_BANK_KEY is the unique key for the BANK_LIST table, that field should be selected, also. If we only use BANK_LIST_BANK_KEY as the external ID, the BAPI will not receive any import parameters and will not execute correctly.

These two combined fields allow the records to be uniquely identified (with BANK_LIST_BANK_KEY) and allows the BAPI to execute correctly (BANK_CTRY).

Some BAPIs require many import parameters and may hit a Salesforce Connect limitation in external ID length. In this case, it is necessary to either use a simpler BAPI or create a BAPI wrapper that Salesforce Connect can integrate easily with.

Key Separator

When a BAPI has multiple keys, the key data is separated by a colon (:). Any colon in the data will be escaped. 

SOQL Queries with External Objects

Overcast Salesforce Connect scenarios create standard external objects that operate and integrate with Salesforce applications using SOQL queries and DML operations. Write support is determined by the external system and API.

Open the external object in Salesforce Setup to get the object and field API names for writing SOQL queries.