After completing this unit, you’ll be able to:
- How to pass data from a screen and apex class to invokeCallout
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.
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.
- From Screen:from screen means that you have to write apex code to read data from screen first and then put into the map.
- 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.
Step5: check result on message board