Wednesday, July 24, 2019

#724 OIC - Salesforce Adapter - Bulk API

As the name suggests -
It allows one to perform Bulk Data Operations:
Inserts, updates, upserts, or deletes of a large volume of records.

For those interested, the SFDC Bulk API Doc is here

An extract from the aforementioned -

Bulk API is based on REST principles and is optimized for loading or deleting large sets of data. You can use it to query, queryAll, insert, update, upsert, or delete many records asynchronously by submitting batches. Salesforce processes batches in the background.

SOAP API, in contrast, is optimized for real-time client applications that update a few records at a time. You can use SOAP API for processing many records, but when the data sets contain hundreds of thousands of records, SOAP API is less practical. Bulk API is designed to make it simple to process data from a few thousand to millions of records.

The easiest way to use Bulk API is to enable it for processing records in Data Loader using CSV files. Using Data Loader avoids the need to write your own client application.

Data Loader is an app you can download from your Salesforce instance -

Leveraging the Bulk API via OIC -

First, an extract from the Oracle SFDC  adapter docs -

The Salesforce Bulk API enables you to handle huge data sets asynchronously with
different bulk operations. For every bulk operation, the Salesforce application creates
a job that is processed in batches.
A job contains one or more batches in which each batch is processed independently.
The batch is a nonempty CSV/XML/JSON file that is limited to 10,000 records and is
less than 8 MB in size. Because the batches are processed in parallel, no execution
order is followed. A batch can contain a maximum of 10,000,000 characters in which
5,000 fields in a batch are allowed with a maximum of 400,000 characters for all its
fields and 32,000 characters for each field.

Here is a simple example where I will read a file of Leads from an ftp server and leverage the SFDC Bulk API to insert them into SFDC.

BulkLoadLeads is configured as follows -

I upload a test csv file to my ftp server -

As this is a scheduled orchestration, I click Submit Now -

As you can see, this is the second run -

I go to Monitor Bulk Data Load Jobs in Salesforce -

#723 OIC - Salesforce Adapter - Invoking APEX web services

APEX - a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on Salesforce servers in conjunction with calls to the API. Using syntax that looks like Java and acts like database stored procedures, Apex enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages. Apex code can be initiated by Web service requests and from triggers on objects.

Full SFDC docs here

So APEX is value-add I can create in my SFDC environment - here is a simple example -

I have created the APEX class - NiallCEmailManager and have tested it.

I now need to amend the code to expose it as a web service -

I now check for the APEX class in SFDC - Setup

I can now generate the WSDL -

and  save locally -

Create the Integration in OIC

The integration has a REST trigger.
Request contains a valid email address.

SFDC Connection configured as follows -

Mapping -

I have hard-coded subjects and messages.

addresses is set to Source email

I activate and test via Postman

Tuesday, July 23, 2019

#722 OIC - Salesforce Adapter - Perform Core or Utility Operations (ConvertLead)

SFDC Core and Utility Services are documented here

The OIC SFDC adapter supports a subset of these -

Convert Lead - Converts a Lead into an Account, Contact, or (optionally) an Opportunity.

Get Deleted - Retrieves the IDs of individual objects of the specified object that have been deleted since the specified time

Get Server Timestamp - Retrieves the current system timestamp (Coordinated Universal Time (UTC) time zone) from the API

Get Updated - Retrieves the list of individual records that have been updated (added or changed) within the given timespan for the specified object.
Use this for data replication applications to retrieve a set of IDs for objects of the specified object that have been created or updated within the specified timespan.

Get User Info - Retrieves personal information for the user associated with the current session, e.g. full name, email etc.

Merge - Combines up to 3 records of the same type into 1 record. The input is an array of MergeRequest elements, each of which specifies the records to combine e.g. merging contacts or leads.

Process - Submits an array of approval process instances for approval, or processes an array of approval process instances to be approved, rejected, or removed.

Send EmailImmediately sends an email message - counts against the daily email limit.

Undelete - Undeletes records from the Recycle Bin.
Details on the Recycle Bin here

Now to an example - 

Convert one of our Leads to an Account and Contact

Here is the OIC invoke configuration -

Here is the mapping -

The request includes the leadId of my contact, Jimmy.
convertedStatus has been hard-coded as follows -

The response mapping -

I have mapped accountId, contactId, success from Source to the Target fields.

I test via Postman -

I validate in SFDC -

Jimmy is now a Contact -

The Hare of the Dog Pub is now an Account -

Note also that an Opportunity has been created for this account.

#721 OIC - Salesforce Adapter - Events triggering Integrations

Today a simple demo of using the SFDC adapter as a trigger in an OIC integration.
In other words, automatically calling an OIC integration when a business event occurs.

Here an OIC integration will be triggered on the creation of new Irish leads in SFDC.

Below is what one sees on dropping the SFDC adapter as a Trigger in OIC -
Essentially instructions on completing the pre-requisites in SFDC to make this work.

SFDC calls OIC when an event occurs, e.g. New Irish Lead.
For this you have to configure some stuff in SFDC -

an Outbound Message - to call OIC - this will include specifying the OIC url and the object/fields you want to send e.g. Lead name, email etc.

a Workflow Rule - defining when to make the call e.g. on lead creation when the lead has an Irish address.

Create Outbound Message and Workflow Rule

I select Lead -

Note: I enter a dummy Endpoint URL.
This I will replace later with the concrete OIC url, once the integration has been activated.

I also specify the Lead fields to send -

I save the outbound WSDL to a file for later use in the OIC Trigger configuration -

I now create a Workflow Rule in SFDC -

This rule will fire for new Leads with a country address = Ireland
(set in Rule Criteria)

I now bind this to the outbound message I previously created -

Last step is to activate the rule -

Now back to the Trigger configuration in OIC -

Create Integration in OIC

As you can see, I have uploaded the outbound WSDL file.

The above is just telling me to update SFDC Outbound Message definition with the correct URL,
once the integration has been activated.

In this case, I will just write the new leads to a file on an ftp server.

I start by setting the Tracking field -

I implement as follows -

Mapping Source, i.e. the data sent from SFDC, is as follows -

I activate and update the SFDC workflow definition with the concrete integration URL.

I now test by adding a new Lead in SFDC -

I monitor in OIC -

I check my ftp server -

and there he is, the bauld Dermot.