Tutorial

  1. Home
  2. Docs
  3. Tutorial
  4. 41. How to build real-time outbound interface?

41. How to build real-time outbound interface?

Learning Objectives

After completing this unit, you’ll be able to:

  • Describe what real-time outbound Interface is.
  • How to build real-time outbound interface

Introduction

This concept is about outbound interface processing. Real time outbound interface we can do in different way i.e Using a button, Using trigger, Using the process builder.

 What is real -time outbound processing?

For outbound processing, we need to categories in two flavor.

  • Synchronous -> apex code wait for the response of the http callout
  • Asynchronous -> apex code doesn’t wait for the response of the http callout. It can have a response which is an asynchronous response. This response can come at any time.

Synchronous interface mostly has a response which means that we will create a response interface to handle the response. An asynchronous interface mostly doesn’t have a response. But this is not true for all cases. We could have an asynchronous interface which has a response interface. In this case, the apex code doesn’t wait and get blocked. The response will come back at a later time. In this case, we have an asynchronous scenario with an asynchronous response. But for a synchronous interface, we should always expect to have a response and the apex code is waiting as long as it will take until the response is coming back. If the response doesn’t come back at the allowed time e.g. 120 sec. then we will get a governor limit exception time out.

The steps in the asynchronous processing are as follows:

  1. Execute the soql statement from the interface to read the business data
  2. Create the message (outbound message) with status „Pending“
  3. Do request mapping
  4. Convert to xml, json and send it out h an adapter.
  5. Check the result of the http callout and update the status of the outbound message

For the synchronous processing the steps are as follows:

  1. Execute the soql statement from the interface to read the business data
  2. Create the request message (outbound message) with status „Pending“
  3. Do request mapping
  4. Convert to xml, json and send it out through an adapter e.g. make a http callout.
  5. Wait for the response. When the response comes then parse the response and call the inbound processing to execute the response interface

For the asynchronous scenario, we need the outbound message to reprocess it again. For synchronous scenario, we normally and mostly do not need the outbound message to reprocess. If the call for example to Google web service fails the user will issue the call again. This is true when the end user carries the action. But what is when the action is not carried by the user but for example from a trigger or process builder process? In this case, a background process is the trigger of the action and if something going failed there is no user to repeat the action again. Therefore, in this case, we need an outbound message so that the reprocessing job or the user can reprocess the call again. Technically we can handover the interface processing to the future, queueable or batch apex.

How to build real-time outbound interface

Realtime outbound interface we can do in different way:

  1. Using a button on for example a sObject Account and put the code to do the callout with invokeCallout2().
  2. Using trigger. In this case it fires when a record is changed.
  3. Using the process builder. This is quite the same as trigger. The difference here is that you have a graphical design tool to define the condition when a record should be sent.

How to create real time outbound Interface using Button

This feature use our invokeCallout2() method. This method support   SAP, SAP-PI, SAP-R/3,SFDC2SAPPI, SOAP, REST adapter types. Response  could be text of JSON, XML, List<Map<String,String>> based on given flag parameters in CallOutControl and Apex of each adapter handle setting when execute callout.  InvokeCallout2() method support different mode:

1. SYNC
2. FUTURE
3. BATCH
4. AUTO

We get real time response in SYNC mode only.

Input Parameters:

-integrationName:  Integration Name

-interfaceName:  Interface name

-ids:  Collection of sObject id

-mode:  SYNC, FUTURE, BATCH, AUTO

CallOutControlFlagCalloutResponse (Attributes)SAPSAP-PISAP-R/3SFDC2SAPPISOAPREST
returnJSONCompletetrueString payloadJSONnonononoyesyes
returnXmltrueString payloadXMLnononoyesyesyes
returnListRecordtrueList<Map<String,String>> recordsyesyesyesyesyesyes
returnIMessagestruenononononono
actionDoIntegratefalseDoes not process interface invoke call In/Out
actionDoMappingtrueDoes nothing with this flag
isCreateMessagefalseDoes not upsert message only in mode SYNC, Otherwise message will upsert.
isBypassDMLtrueDoes not upsert messages, interface, log file

Step 1: Create Outbound interface and do mapping 

We have to create an outbound interface and mapping data as business required as shown below:

We have to select fields on which we have to built query. For example here we have selected three fields  AccountNumber, BillingCity, and Name. And mapping data.

Click on outbound interface to show detail and do mapping data as shown below:

Step 2: Create adapter and create property such as endpoint, username, password

Please configuration adapter type as screen below.You need to createProperty such as endpoint, username, password

-Add this adapter to outbound interface

Step 3: Executed apex code in developer console

Navigate to Developer Console->Debug->Open Execute Anonymous Window->Type code.

Type code and execute it: I test with two different account

skyvvasolutions.CallOutControl c=new skyvvasolutions.CallOutControl();

c.isBypassDML=false;

List<Id>myList = new List<Id>();

myList.add(‚0017F00000PybaW‘);

skyvvasolutions.IServices.invokeCallout2(‚SF-Test‘,’Account2-Test‘,myList,’SYNC‘, c);

//———————Execute once it will show one complete message as below———————–

skyvvasolutions.CallOutControl c=new skyvvasolutions.CallOutControl();

c.isBypassDML=false;

List<Id> myList1 = new List<Id>();

myList1.add(‚0017F00000QGoOe‘);

skyvvasolutions.IServices.invokeCallout2(‚SF-Test‘,’Account2-Test‘,myList1,’SYNC‘, c);

//———————Execute again it will show one complete message as below———————–

*Note: if we execute invokecallout2 two line with different account id in once execute it will show one message is fail and one more message is completed.

Other case: if we execute invokecallout2 two line with the same account id in once execute it will show only one message is fail because it is duplicate 

Check it in Message monitoring.

How to create real time outbound Interface using Trigger

In integration admin, there is  new tab called „SKYVVA Trigger“ which allows the user to configure in a graphical user interface the following settings:

– Select box „Triggering Method“: Button, APEX Trigger
– Select box „Mode“: Immediate, Batch
– SFDC object: List of all Objects in the Org
– Interface to trigger: List of all Interfaces in the Org

SKYVVA Trigger tab uses to generate script trigger automatic for Button and Apex Trigger. Go to “Integration Admin” tab > click on the tab “SKYVVA Trigger”

It can generate two kinds of script:

  •  Generate Script Trigger Button
  • Generate Script Trigger Apex

   1. Generate Script Trigger Button

  • Select Trigger Type “BUTTON”
  • Select your Integration Name
  • Select your Interface Name (show only outbound interface)
  • Select SObject Name
  • Select Trigger Mode: Sync,Future,Batch
  • Click button “Generate Script”
  • Now you will see the script trigger button in the box and can copy to use it

2. Generate Script Trigger Apex

  • Select Trigger Type “APEX TRIGGER”
  • Tick Trigger Event (can tick more than one)
  •  Select your Integration Name
  •   Select your Interface Name (show only outbound interface)
  •  Select SObject Name
  •  Select Trigger Mode : None,Auto,Future,Batch
  • Click button “Generate Script”
  • Now you will see the script apex trigger in the box and can copy to use it
  • In the script, change to your own name <trigger name> to your own name

Note: At the last select with Trigger Mode, button “Generate Script” will visible

How to create real time outbound Interface using Process builder

Process Builder is a Salesforce’s point-and-click tool that lets you easily automate if/then business processes and see a graphical representation of your process as you build. Every process consists of a trigger, at least one criteria node, and at least one action. You can configure immediate actions or schedule actions to be executed at a specific time. To keep things simple, this unit focuses on the most common process type: Record Change, which mean the process, will start when the records are created or edited.

  • Create process builder to create CP Record

Select SKYVVA apex API

Add input definition

Setting apex variable values:

integrationName: integration name

interfaceName: interface name:

isCreateCPRecord: True (False, if value is not specified)

recordIds: salesforce sObject.Id (i.e Account.Id)

You can test modification account from the screen and Save.

I have executed mass update 10 account in developer console then got 10 CP records

  • Process Builder executes callout.

You can edit account on screen the save, then check message on message-monitoring

 

 

 

 

 

 

 

 

 

Was this article helpful to you? Yes No

How can we help?