VOOZH about

URL: https://www.cdata.com/kb/tech/salesforce-odata-azure-logic-app.rst

⇱ Trigger Salesforce IFTTT Flows in Azure App Service


Trigger Salesforce IFTTT Flows in Azure App Service

πŸ‘ Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Automate IFTTT (if-this-then-that) workflows for Salesforce with standard wizards in Logic Apps.

Through standards-based interfaces like OData and Swagger, the CData API Server provides a native experience in Logic Apps and Power Automate with Salesforce. OData enables real-time connectivity to data; Swagger enables scaffolding, or code generation, of wizards in Logic Apps and Power Automate, as well as scaffolding Power Apps. This article shows how to add Salesforce to an IFTTT (if-this-then-that) workflow in a Logic App.

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

If you have not already done so, download the CData API Server. Once you have installed the API Server, follow the steps below to begin producing secure Salesforce OData services:

Connect to Salesforce

To work with Salesforce data in a Logic App, we start by creating and configuring a Salesforce connection. Follow the steps below to configure the API Server to connect to Salesforce data:

  1. First, navigate to the Connections page.
  2. Click Add Connection and then search for and select the Salesforce connection. πŸ‘ Selecting a data source (SQLite is shown)
  3. Enter the necessary authentication properties to connect to Salesforce.

    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.

    πŸ‘ Connecting to a datasource (SQLite is shown)
  4. After configuring the connection, click Save & Test to confirm a successful connection.

Configure API Server Users

Next, create a user to access your Salesforce data through the API Server. You can add and configure users on the Users page. Follow the steps below to configure and create a user:

  1. On the Users page, click Add User to open the Add User dialog.
  2. Next, set the Role, Username, and Privileges properties and then click Add User. πŸ‘ Configure a new user
  3. An Authtoken is then generated for the user. You can find the Authtoken and other information for each user on the Users page: πŸ‘ API Server user settings

Creating API Endpoints for Salesforce

Having created a user, you are ready to create API endpoints for the Salesforce tables:

  1. First, navigate to the API page and then click Add Table . πŸ‘ Add tables
  2. Select the connection you wish to access and click Next. πŸ‘ Select the connection (SQLite is shown)
  3. With the connection selected, create endpoints by selecting each table and then clicking Confirm. πŸ‘ Adding tables from the connection (SQLite is shown)

Gather the OData Url

Having configured a connection to Salesforce data, created a user, and added resources to the API Server, you now have an easily accessible REST API based on the OData protocol for those resources. From the API page in API Server, you can view and copy the API Endpoints for the API:

πŸ‘ API Endpoints

Access Salesforce in a Logic App

You can use the API Server in a Logic App to create process flows around Salesforce data. The HTTP + Swagger action provides a wizard to define the operations you want to execute to Salesforce. The following steps below show how to retrieve Salesforce data in a Logic App.

If your table has a column containing the creation date of a record, you can follow the steps below to write a function to check the column values for any new records. Otherwise, skip to the Create a Logic App section to send out emails to entities that match a filter.

Check for New Salesforce Entities

To find new Salesforce entities since a certain time, you can write a function that retrieves a datetime value for the start of the interval:

  1. In the Azure Portal, click New -> Function App -> Create.
  2. Enter a name and select the subscription, resource group, App Service plan, and storage account.
  3. Select your Function App and select the Webhook + API scenario.
  4. Select the language. This article uses JavaScript.
  5. Add the following code to return the previous hour in a JSON object:
    module.exports = function (context, data) { 
     var d = new Date();
     d.setHours(d.getHours()-1); 
     // Response of the function to be used later.
     context.res = { 
     body: { 
     start: d 
     } 
     }; 
     context.done(); 
    };
    

Add Salesforce to a Trigger

Follow the steps below to create a trigger that searches Salesforce for results that match a filter. If you created the function above, you can search for objects that were created after the start of the interval returned.

  1. In the Azure Portal, click New and in the Web + Mobile section select Logic App and select a resource group and App Service plan.
  2. You can then use the wizards available in the Logic App Designer, which can be accessed from the settings blade for the Logic App. Select the Blank Logic App template.
  3. Add a Recurrence action that will poll for the Salesforce objects. This article polls every hour. Select the timezone -- the default is UTC.
  4. Add a function action: Expand the menu in the Add Action dialog and select the option to show Azure functions in the same region. Select the Function App you created earlier and select the function that returns the interval start.
  5. Enter an empty pair of curly brackets, "{}", to pass an empty payload object to the function.
  6. Add the HTTP + Swagger action and enter the swagger URL of the API Server:
    http://MySite:MyPort/api.rsc/@MyAuthtoken/$oas
  7. Select the "Return Account" operation.
  8. Use the descriptions for each property to specify additional parameters such as the columns to retrieve, filters, etc. Below is an example filter:

    Name eq 'GenePoint'

    The API Server returns the descriptions and other documentation in the swagger document. You can find more information on using the OData API and supported OData in the API Server help documentation.

  9. To use the datetime value returned from the getInterval function, use the "ge" operator with a datetime column in the Account table and select the Body parameter in the dialog. Note that quotes must be used to surround the datetime value.

    πŸ‘ An OData filter on the results of an Azure Function App, getToday. (Salesforce is shown.)
  10. Switch to Code View and modify the $filter expression to extract the property containing the start of the interval. Use the syntax '@{body('MyFunc')['MyProp']'.

    "getAllAccount": {
     "inputs": {
     "method": "get",
     "queries": {
     "$filter": "CreatedDate ge '@{body('getInterval')['start']}'"
     },
     "uri": "https://MySite:MyPort/api.rsc/@MyAuthtoken/Account"
     }
    

You can now access Salesforce as data sources and destinations in your workflows.

Email New Records

Follow the steps below to email a report with any new Account entities.

  1. In the Logic Apps Designer, add an SMTP - Send Email action.
  2. Configure the necessary information for the SMTP server.
  3. Configure the From, To, Subject, and Body. You can add parameters from the Salesforce columns returned.

Click Save and then click Run to send email notifications on any Salesforce records created in the last hour.

πŸ‘ Dynamic columns added to template the body of an email. (Salesforce is shown.)

Ready to get started?

Learn more or sign up for a free trial:

CData API Server