Invoke with Apex
Last updated
Last updated
Using Apex, you can invoke the Integration Channel to make callouts to an external system. Here, you have two ways to invoke integration channel in Apex :- 1. Simulate the Integration Channel in synchronous mode 2. Simulate the Integration Channel in Asynchronous mode 1. Simulate the Integration Channel in synchronous mode
It will execute the integration channel in synchronous mode you can refer to below.
How to use integration channel in Apex
To simulate the Integration channel in apex, use the following lines of code. lwapic.ICChannelRequest instance = new lwapic.ICChannelRequest(); instance.channelName = 'Push_Data_to_Power_BI'; // pass the channel API name //instance.requestPayload = '{"rows":[{"StageName":"Prospecting","Name":"Sobha 200 OK"}]}'; // If required pass the body instance.queryParams = value 1, value 2,value 3; //If you want to pass values dynamically eg :- {0},{1},{2},... are set in endpoint or query params of integration channel and comma(,) is the request data separator List<lwapic.ICChannelRequest> resList= new List<lwapic.ICChannelRequest>(); resList.add(instance); List<lwapic.ICResponseWrapper> respWrapList = lwapic.ICControllerSync.execute(resList); If Integration channel is excepting some inputs to be passed while simulating the channel at runtime, in the above code, you have global class named ‘ ICChannelRequest ’. In the same class, there are several global variables( recordId, queryParams, requestPayload, etc. ) by which you are going to set the values to the channel at runtime. Navigate to the developer console by using the setup gear icon. Then, for understanding the process, navigate to execute anonymous window and paste the above code to simulate the channel. You can use the above code in any class or any method as per the requirement, as shown in the image below.
*Note :- After simulating the integration channel in synchronous mode, you can obtain the response of the channel using the global class named 'ICResponseWrapper' to use it further. 2. Simulate the Integration Channel in Asynchronous mode It will execute the integration channel in asynchronous mode. You can refer to below
Similar to synchronous mode, only change is instead of lwapic.ICControllerSync.execute(resList); you need to use lwapic.ICControllerASync.execute(resList); in Apex to simulate the channel in asynchronous mode, as shown below. lwapic.ICChannelRequest instance = new lwapic.ICChannelRequest(); instance.channelName = 'Push_Data_to_Power_BI'; // pass the channel API name //instance.requestPayload = '{"rows":[{"StageName":"Prospecting","Name":"Sobha 200 OK"}]}'; // If required pass the body instance.queryParams = value 1, value 2,value 3; //If you want to pass values dynamically eg :- {0},{1},{2},... are set in endpoint or query params of integration channel and comma(,) is the request data separator List<lwapic.ICChannelRequest> resList= new List<lwapic.ICChannelRequest>(); resList.add(instance); lwapic.ICControllerASync.execute(resList); // Don't store in any variable as Sync execution because it doesn't return any response in ASync Execution
*Note :- After simulating the integration channel in asynchronous mode, no output will be immediately available since it operates asynchronously.