Introduction #
Agent REST Adapter is a feature like REST Adapter, but it has more power than the REST Adapter. REST Adapter needs the System to have Public API to call out API, but Agent REST Adapter can callout API with Systems that have Public API and Local API.
So it is useful for users who want to keep data in the local System. To use Agent REST Adapter, we need to have an Agent application to store in the local machine meaning that Agent REST Adapter is like a bright to connection Salesforce to the Agent machine and the Agent machine connects to Backend applications.
Example: In a Real business scenario, we want to make our data secure, so we need to use a local network zone to install Agent machine and Backend applications such as SAP or Oracle. We do like this because we don’t want any systems to access our System, and it is the technique to protect our data from being safe.
The processing of Agent REST Adapter #
Here’s the picture of the processing of Agent REST Adapter.
In this picture, we can see Salesforce and SKYVVA are in the Internet zone where Agent Machine and Backend applications are in the Local network zone. So when we callout from Salesforce to Backend applications, it will access Agent Machine and Agent Machine send data to Backend applications.
The agent is responsible for making connections with the inside enterprise and then connecting with Salesforce (Internet zone). This Adapter is really helpful for users to send data to salesforce to local backend applications.
How to create a REST interface using the Agent REST Adapter? #
How to use Agent REST Adapter for callout data from salesforce. We also learn about how to callout data and get a response message and we will learn how to use fault Interface when the other system has a fault message.
Case 1 #
Handle API message without Response Interface.
Pre-require
- Create or Upload Message Type REST.
- Configuration Agent control board.
- Create Adapter Agent REST.
- Create Integration and Outbound Interface.
Step 1: Create or Upload Message Type REST.
- Go to Metadata-> click button Import MetaData Provider.
- Click upload files (Put metadata and click OK)
- Here’s REST Message Type. Click this to download.
– RESTVersion2_skyvvasolutions__MetaDataProvider__c (5)
Step 2: Create integration and outbound Interface.
- Create an outbound Interface link with Message Type.
- Do mapping
Step 3: Configuration Agent Control Board.
- Go to Integration detail => click AGENT Control Board.
- Click on Agent Control Board Tab
Since the user now completely understand; How to use the Agent Control Board, by hitting the upper link, now we understand the Architect of the Agent Control Board now follows below on Salesforce org.
Step4: Create Adapter Agent REST
- Click adapter tap on Agent Control Board.
- Click New button
- Configure an Agent Adapter Soap
Fill name, choose Type =Agent Soap, Direction= outbound, choose XML payload, Operation= POST, fill username and password, and choose Adapter_instance.
- Here’s an example.
Step 5: put the adapter into Interface.
Step 6: Callout v3 with Apex code.
- Here’s code callout.
skyvvasolutions.CallOutControl c = new skyvvasolutions.CallOutControl(); c.returnJSONComplete=true; c.actionDoIntegrate=true; c.isCreateMessage=true; String[] ids= new String[]{‘0011x000015BR30AAG’}; skyvvasolutions.Iservices.invokeCalloutV3(‘IntegrationName’,’InterfaceName’,ids,’SYNC’,c); |
- Go to deveoper console => Debug => Open Execute Anonymous Window => copy the code abouve and click Execute.
- Go to Monitor to see the result
Case 2 #
Handle API Message with Response Interface.
In this case, we just need to create a Response Interface using Soap Message Type.
Pre requires
- Create or Upload Message Type REST. (We have configured in case1)
- Configuration Agent control board. (We have configured in case1)
- Create Adapter Agent REST. (We have configured in case1)
- Create Integration and outbound Interface. (We have configured in case1)
- Create Inbound Interface
How to Handle API message with Response Interface?
In this case, we just need Inbound Interface one more for do response. Because of Case 1, we have configuration some pre-required already.
- Here’s the response Interface.
- Do mapping.
Step 2: Go to Interface Request and put the Response Interface in the field’s response Interface.
- Go to Interface Request.
- Scroll down to see the field’s request Interface. Click this pencil.
- Put response Interface in it, Example below. Click the save button.
Step 3: Callout v3 with Apex code with Request Interface.
- Here’s code callout.
skyvvasolutions.CallOutControl c = new skyvvasolutions.CallOutControl(); c.returnJSONComplete=true; c.actionDoIntegrate=true; c.isCreateMessage=true; String[] ids= new String[]{‘0011x000015BR30AAG’}; skyvvasolutions.Iservices.invokeCalloutV3(‘IntegrationName’,’InterfaceName’,ids,’SYNC’,c); |
- Here’s example.
- Go to Monitor to check the result.
Case 3 #
Handler Over Fault Response.
- In this case, we use two Interfaces like Inbound Interface for Response and Outbound Interface for Request. The process of these cases is to put the Response Interface, which is fault Message Type, into the Request Interface.
- Example. We have an outbound Interface and put the fault Interface that has message Type fault_SystemError in the outbound Interface. When the callout V3 is met the situation, System Error, so the Inbound Interface will respond to the fault message to tell the user that the Callout has a problem with the system Error.
- Create or Upload Message Type REST with Fault Message Type. (We have configured in case1)
- Configuration Agent control board. (We have configured in case1)
- Create Adapter Agent REST. (We have configured in case1)
- Create Integration and outbound Interface. (We have configured in case1)
- Create Inbound Interface as a fault Interface.
Step1: create Inbound Interface as fault Interface.
- Go to Integration => create Interface.
- Here’s the Inbound fault Interface.
- Do mapping
Step 2: put fault interface in request interface.
- Go back to request Interface (Normal case)
- Scroll down to find the fault Interface field.
- Put the fault Interface in this field.
Step 3: callout with apex code.
- Here’s an example.
- Go to monitor to check results.
Case 4 #
Handle multiple different fault messages
Pre-require:
- Create or Upload Message Type REST with Fault Message Type. (We have configured in case1)
- Configuration Agent control board. (We have configured in case1)
- Create Adapter Agent REST. (We have configured in case1)
- Create Integration and outbound Interface. (We have configured in case1)
- Create two Inbound Interfaces for fault interfaces.
We have created a Fault Interface system error already so now we need to create two more fault Interfaces.
Step1: Go to Integration and create Fault interfaces.
- Create Inbound fault Interface and linked with fault_AdminBlockException and click button save.
- Do mapping.
Step2: Put Outbound Interface Name in fault Interface of Every Response Interfaces.
- Make sure that the request Interface doesn’t have a fault interface in their field.
- Here’s the request Interface.
- Scroll down to make sure that this interface doesn’t have a fault Interface.
- Here’s Response System Error Interface. (That we have created above)
- Scroll down to put request interface in field fault Interface.
We need to other Response fault Interface like the same way.
- Here’s AdminblockException fault Interface.
- Scroll down to put the request interface in the field fault interface.
Step 3: Go to Request Interface to see response fault Interfaces related.
- Go to Related Interface of request Interface.
- Scroll down to see both fault Interfaces have related to this request Interface.
Step4: callout with apex code.
- Go to the message monitor to check the result.
Case 5 #
How to use the REST v4 API to push data to Agent?
- Our V4/integrate rest variant supports JSON and XML and therefore it is possible to pass the Rest envelope XML or JSON to the body of the v4/integrate. This means that for invoking the SKYVVA API we use only the rest variant ../services/apexrest/skyvvasolutions/v4/Integrate with either XML or JSON payload.
- In the URL of V4 API, the query parameter is added in URL only.
We have two types of response:
1. standard response
2. custom response using the response (outbound) interface to do the mapping
if we want to get data from the response interface then we need to do mapping for the response interface and link it to the request interface. Only data send from the input will return back a response. If we want anything other than the input data then we have to use VLOOKUP formulae in the response mapping.
- Click on Agent Control Board Tab
Since the user now completely understand; How to use the Agent Control Board, by hitting the upper link, now we understand the Architect of the Agent Control Board now follows below on Salesforce org.
–How to create a REST interface using the Agent REST Adapter?
Then Go to the adapter tab and create an Inbound adapter. Here we are using the Rest adapter for the Inbound direction.
Step 2: Create Inbound Interface. To create an Inbound interface refer tutorial from our website: How to create Interface?
- Select Metadata which you have created earlier: ex: V4Integrate
- Select Istructure Repository
- Select Message Type
- Select Inbound adapter: agent Rest adapter
- Save the Interface.
Step3: Do mapping and save it.
- Make sure cache should be created
- Check to cache for each object: Integration, interface, mapping.