Skip to main content

Invoking Apex Callouts through Visual Flows

Few weeks back I was attending a Webinar on Advanced Flow From SFDCBill(Product Manager Flows Salesforce.com) .I was quite surprised to discover flows are very powerful feature provided by the platform for the administrator to configure the business logic .

My friend Rakesh has been blogging lot of use cases of flows for Salesforce 1 and using chatter objects .You can refer his blog for more details on the work he has done .I have learned lot from those and I am thankful to him for sharing his experience with visual flows through his blog


http://rakeshistom.wordpress.com/category/workflow-rule/visual-workflow-flow/


One of the things that came was invoking callouts or webservices through flows and SFDCBill was able to communicate the design that one needs apex and process plugin for invoking callouts directly from the flow .I did a quick online search to see if this has been demonstrated  and was not able to get some good resource so i thought of sharing a sample tutorial on how to invoke callouts from flows directly.

The more information on the process plugin can be obtained from below URLs ,

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_process_plugin.htm
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_process_plugin_example_lead_convert.htm

The Process plugin is an apex Interface and that needs to be implemented in order to pass request into the apex class from the flow input or screen and the apex interface returns the response back to the flow.

Lets discuss how we can make a web service or apex callouts from flow directly .

1)Our first step will be to write the apex plugin class that makes a webservice callout to external website and process and makes the data ready for passing back to the flow.

For webservice part I have taken a sample REST service provided for free for learning purpose from the website http://api.wunderground.com/weather/api/

The web-service takes input of state and city of US and outputs current weather condition in the form of JSON objects .Note that you need to sign up and generate an API key for your use .

The input of state and city can be taken from flow screen and it can be passed directly as request parameter to the apex class .

Here is the complete apex class for the flow plugin



2)For JSON parsing ,I have used another class shown below ,which handles parsing of the data .This can be easily generated using https://json2apex.herokuapp.com/ by providing sample response JSON.

Lets dig into the creation of flows ,

Visual workflow basics can be studied from following resources 

http://help.salesforce.com/help/pdfs/en/salesforce_vpm_implementation_guide.pdf
http://www.salesforce.com/us/developer/docs/workbook_vf/workbook_vf.pdf

3)We will need below three components 

i))Input Screen to take data of city and state from User need as input for our webservice
ii)WeatherAppApex Plugin we have just developed using apex
iii)Output Screen to display the result



The input screen will have two fields to capture input 



The Apex Plugin will have a mapping for both input and output from result.The below screen shots show the input and output mappings .Note for output mapping for further usage of output  parameters flow variables are created




The output Screen is last piece to display the results .

Now lets see the outcome of this work in below video



I hope you enjoyed this tutorial and looking forward to your comments below .

Please note error handling in code and Test classes are left as it was just a POC code .Be careful to take care of all these when implementing for client code .

Happy Coding !!!

Popular posts from this blog

TLS 1.0 has been disabled For Sandbox - Salesforce

Salesforce has finally disabled TLS 1.0 in sandboxes .This is in preparation for disablement later in 2017 for PRODUCTION instances .

Now this would have not impacted your integrations in PRODUCTION org but if your integration is broken in your sandbox ,this means you have only few months to sort this and fix before this affects your integration for PROD live users .
Before we deep drive on how to possibly fix this and work with your external systems to figure solution ,lets first understand what is TLS and why did SFDC moved to 1.x and had to disable TLS 1.0
TLS 1.0 Explained























TLS 1.1 Improvements 
Added protection against cipher-block chaining (CBC) attacks. Support for IANA registration of parameters.

Clearly TLS 1.1 is more secure(Compared to 1.0) and protects salesforce resources against CBC attacks .
Identify if this change broke anything .The things that can be affected in your instances are as below Web requests to Salesforce URLs that require authenticationWeb requests to the login pag…

Opening Modal Using Lightning Component Framework of SFDC

One of my friend from India threw a challenge .The challenge was to open a modal by using latest and greatest lightning components framework and modals design from SLDS .For the love of community I thought of sharing the entire code base that I did .

So here we start ..

Business Use Case - Need a handy SalesLeader board component that can be used to display the Sales revenue generated by each sales rep for current year in the order of decreasing total revenue .On click of the tile ,we will show detail opportunity list aggregating the revenue .

The component can be dragged in lightning design experience or in App builder lightning Page .

Video Demonstration-



SalesLeaderBoard from Mohith Kumar Shrivastava on Vimeo.








Frameworks Used -
Lightning Design Systems (SLDS) for CSSLightning Component Framework for client side logicApex aura enabled class for backend logicApproach
The component hierarchy is very important to imagine or mindmap before we dig deeper- SalesLeaderMain
    -SalesLeaderBoard
    …

Writing Test Classes For Apex Rest Service

I came across a question in a developer community on how to write Unit Test Classes for the Rest API service for POST HTTP calls

Unit Test Classes for REST API following link is very useful and inspired by this jeff had an article on his blog on how to write the test method for same .

Here is the Jeff Blog Link Test Class for REST API(Good reference for GET Rest Services)


In one of my previous blog post i demonstrated how to use native parsing technique for Rest api for User Defined Type
I wrote the Test class for the same and this post is helpful for all those searching for how to write test classes for apex rest service annotated with POST Call
Here is the Rest Service Class for which i attempted the test class
@RestResource(urlMapping='/DemoUrl/*') global with sharing class MyRestResourcedemo { global class RequestWrapper{ public Account acct; public Contact[] cons; } global class ResponseWrapper { public String StatusCode; …