Tutorials

  1. Home
  2. Docs
  3. Tutorials
  4. 71. How to use the API invokeCallout2() to pass data from the screen and apex class?

71. How to use the API invokeCallout2() to pass data from the screen and apex class?

Learning Objective:

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

  • How to pass data from a screen and apex class to invokeCallout

Introduction

We can pass data from the screen and apex class where the data is going into the mapping instead coming from the database through the select statement in the interface. The caller is an apex class and use the class method invokeCallout2(). Inside this method we have a map parameter where the user can pass name/value pair to the method. The map with the key/value he has to build in the apex caller program.

Why and when to use Screen and apex class to pass data?

We always need to pass the sObject Id to select the data from the database. Here requirement is that user doesn’t want to select data from the database. The data is coming from a screen and they want to make a call to SAP with that data. We have to pass the data which user enters into a screen to invokeCallout2()

They don’t want to have the data to be written into a table in Salesforce. Just whatevere user enters in the screen need to be put a request for the HTTP callout through the SFDC2SAPPI or other adapters. They would use customer class in the outbound interface, so they can extract data themselves.

Note
“The callout is done in mode SYNC only. Future and batch are not needed in this scenario

The data which he build into the map can come from screen or just a constant or data he select himself with select statement. The data is not coming through the select statement in our outbound interface.

There is different way to build the map and fill with data.

  1. From Screen:from screen means that you have to write apex code to read data from screen first and then put into the map.
  2. From Apex:  from apex means that you can set the map with constant value or read from the table or call first google API get the response and put the response into the map.

Steps to use the API invokeCallout2() to pass data from the screen and apex class:

User want to pass data when s/he executes callout api, so only api invokeCallout2 can handle this scenario. here we are using SFDC2SAPPI adapter for outbound processing.

Step1: Create SFDC2SAPPI adapter.

Step2: Create Integration.

Step2: Create Outbound Interface

Step3: Do mapping

Step4: Push data with apex class

  • Go to set up
  • Click on developer console
  • Open Anonymous Window and enter following apex code.

skyvvasolutions.CallOutControl c=new skyvvasolutions.CallOutControl();
Map<String, String> m=new Map<String, String>();
m.put(‘Name’, ‘AC1’);
m.put(‘BillingCity’,’City1′);
m.put(‘BillingCountry’,’DE’);
m.put(‘BillingState’,’State1′);
m.put(‘ERP_DEBTOR_ID__c’,’AC1′);
m.put(‘SAP_Division__c’,’00’);
m.put(‘SAP_Sales_Org__c’,’00’);
c.setPayLoad(m);
skyvvasolutions.IServices.invokeCallout2(‘Shweta’, ‘Account’, null, ‘SYNC’, c);

 

Step5: check result on message board

 

Was this article helpful to you? Yes No

How can we help?