Sunday, 7 September 2014

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 !!!

Sunday, 10 August 2014

Refreshing Parent Window of Inline Visualforce Page from Child Window Opened from Inline Visualforce Page

The problem statement is From Inline Visualforce We need to open a Child window and then from that child window we need to refresh the Parent window of the Child window or redirect Parent window of the child window .

Last night ,I was struggling on how to redirect the Parent Window from the child window that was opened from the Inline window 

I tried hard on how to solve this ,but finally last resort was to post the query on salesforce stackexchange .The below is the link for the same


The error was due to Javascript security of web browser .

I tried the below script on the child window

<script>

  function test(){
     alert('hello');
     window.opener.top.location.href='https://googleflowauth-dev- ed.my.salesforce.com/001900000096agv';
  }

   </script>

Unsafe JavaScript attempt to initiate navigation for frame with URL 'https://googleflowauth-dev-ed.my.salesforce.com/001900000096agv' from frame with URL 'https://googleflowauth-dev-ed--c.ap1.visual.force.com/apex/pagereal'. The frame attempting navigation is neither same-origin with the target, nor is it the target's parent or opener.

The browser security features don't allow navigation from child window directly since visualforce and standard detail page are in different domain.The above error is due to the same feature .

Stackexchange has really expert professionals and Eric suggested me the below solution.I am posting the same so that helps others


The Inline page on the parent window has the below code

<apex:page standardController="Account" extensions="Accountctrl">
<apex:form >
 <script>
  function openwindow(){
       window.open("/apex/pagereal", "myWindow", "width=200, height=100");
 }
  function navigate(){
  window.top.location.href='https://googleflowauth-dev-ed.my.salesforce.com/001900000096agv';//Parent function that redirects
  }
 </script>
<apex:pageBlock >
 <apex:pageBlockSection columns="1" id="Test" >
  <apex:inputcheckbox value="{!test.istest__c}" label="Same as Above">
    <apex:actionSupport event="onchange" rerender="Test" />
</apex:inputcheckbox>
<apex:outputPanel rendered="{!NOT(test.istest__c)}"> 
<apex:inputField value="{!test.Campaign__c}" />
<apex:inputField value="{!test.cust_vendor__c}" />
</apex:outputPanel>
   </apex:pageBlockSection> 
  </apex:pageBlock>

Note that navigate function we will call from the child window and that would navigate parent frame

<apex:page >
 <!-- Begin Default Content REMOVE THIS -->
 <h1>Congratulations</h1>
 This is your new Page

  <script>

 function test(){
     alert('hello');
     window.opener.navigate();//call the parent function from child window and that does the trick
 }

 </script>
  <apex:form >
 <!-- End Default Content REMOVE THIS -->
  <apex:commandButton onclick="test()" value="Test"/>
  </apex:form>
</apex:page>
The child window script will call the opener  window script and that in turn will redirect the parent frame .

Hope this trick will be useful .

Sunday, 20 July 2014

Won Summer Hackathon Bangalore Contest

So here is the good news .Last night we were declared winner of Summer Hackathon Challenge conducted in my city (Bangalore).To know more you can visit the link.First of all let me very clear that I am nothing without my team .It was complete Team work right from Idea to Implementation .




Let me take some time to Introduce you to my fellow colleagues who have worked and taught me so much and I am just a small part .

+MUKUL goel +rashmi t  

Mukul  you can contact him with email mukulgoelster@gmail.com  

Rashmi  you can contact her with email rash2521989@gmail.com


I have never been to Hackathon before and this was really something I thought i should give a try .Nervous I was but when we formed a Team and Started Building ,Confidence level Picked up.

Thanks to Salesforce and BeMyApp .They had organised the event very well .All that we needed to concentrate was to have a working demo of our application on final day of submission.

First Day -When so many Ideas emerge its important to be a good listener .Appreciating each others Idea In a Team certainly helps and its important to keep the team bonding.We stayed whole night in Mukul room and we had pretty much designed UI flows and we were clear on what needs to be done.Its important to have a rough Idea of how you want to shape your Idea and Design and then build .We had completed I would say 25% on day one and all set for second day.

Is sleep Essential?

Yes as humans its important to relax our minds and keep calm .All thanks to my friend mukul who allowed us to take nap for 4 to 5 hours to relax and rest in his personal room.Salesforce allowed to bring sleeping baggage and we could have slept in hall but never wanted to disturb other coders.

Second Day-I saw we were getting exhausted but we kept going .We kept coding and nearly we did our first git commit  in noon .We knew we are close and all we need to do is to keep focused and achieve as many functionality as we want .Our app build was almost there by 10PM on second day .We decided to take rest .

Thanks to mukul ,he did all data clean up and Data search and kept going till 4 AM(Almost third day morning).I was sleeping but mukul kept going

Third Day-It was the most critical day and we did not wanted to loose our focus and all hardwork we had done in these days .I took initiative to come early and do some git commits as I wanted my team to relax and come refreshed.We knew by after noon we need to complete all coding and do final push.

We knew we had shaped our app well ,even if you have small glitches its not worth to keep concentrating as you have small build time and judges know you are human.

So finally we practiced our presentation and we were all set to go to stage and communicate to judges effectively of what our vision and what we have done .

Experience has been amazing and remember attending these hacks broaden and sharpen your skills and give you an edge on where you stand on overall crowd .So you have nothing to loose .

Winning was not motive its to keep focused and do your best and rest may happen magically.



Our App video is here in the below link and we are so excited about this Sales Booster App to take to next level .

http://challengepost.com/software/sales-booster 





Thursday, 12 June 2014

Fun with maps in apex-Part 2

This is an extension of my previous blog on Fun with Maps .So from years of coding now on apex we realize we do lot of repetitive  coding ,The code statements keep repeating but objects ,fields and org keep changing .

So here my problem statement was ,I was using the logic of forming a Map of ParentId and List of Child Records frequently for different triggers and different visualforce classes .Something like below as mentioned in the previous blog.

Here is the sample code that kept on repeating for me
The Object kept on changing for various triggers and classes in my org but the basic logic remained same of forming a collection of Map<Id,List<Sobject>>

Repeating code is never a good pattern and felt need to write an utility that can take care of this .Here is my utility class that can be used ti generalize the concept of collecting parentId and the list of child records (List<childrecord>)

The advantage of this pattern is we dont have to code this logic again and again .It accepts the string of the ParentId Field and also List<sobject> .

Lets see simple use cases of this Utility

1)Usage in Trigger
2)Usage to typecast this class into necessary map

Following illustrates how easy it is to generalize this concept and just write once and avoid repetitive usage on all objects .

Thanks and hopefully you enjoyed this post .Looking forward for your comments and feedback .

Saturday, 10 May 2014

Salesforce.com Certified Technical Architect - Multiple Choice exam

First of all really sorry for not being active on my blog for quite some time and you will find the reason behind the same was my schedule was hectic and I also decided its right time for me to attend Salesforce.com Certified Technical Architect - Multiple Choice exam.

I am glad that i cleared this exam today and thought of sharing some learning's here :)

Its been almost three years on platform and I was involved in wide variety of work ,mostly now on Integration's and Data Migration  Salesforce Projects .So I thought its right time for me to start preparing for at least multiple choice exams as I had confidently submitted the Self Evaluation  and I was informed I am good to go for Next Round .

Again Please don't mail and ask me for dumps as this is against my ethics .Having said that I would definitely provide some insights on what topics one must primarily concentrate while preparing for this Exam .

The Study guide can be obtained from the Certification Website .Now what topics one must concentrate to prepare for this exam.

This exam basically tests your experience on platform ,than anything else so nothing can beat the real experience here .If you have worked on Oauth 2.0,SOAP API's,REST API's,Custom Apex Services ,Network layer Security you should definitely be all good to handle this exam.

The Primary materials I would recommend are below 

http://wiki.developerforce.com/page/Architect_Core_Resources

The above URL will almost give you all the materials and these materials are very good and I read all one by one .They have also arranged it topic wise 

One of my favorite whitepaper is Integration Design Pattern.I downloaded from below URL

https://developer.salesforce.com/page/Integration_Patterns_and_Practices

The Important topics that i felt were as below

1)Integration Design Pattern(Lot of questions on this topic and you will need to be crystal clear on each approach with pros and cons)

2)Oauth 2.0 and various different types of oauth flows thats possible

https://developer.salesforce.com/page/Digging_Deeper_into_OAuth_2.0_on_Force.com

Become familiar  with advantages and disadvantages of each one of those flows that patt has documented

3)Federated and Delegated Authentication

https://developer.salesforce.com/page/Implementing_Single_Sign-On_Across_Multiple_Organizations
https://developer.salesforce.com/page/Single_Sign-On_for_Desktop_and_Mobile_Applications_using_SAML_and_OAuth
https://developer.salesforce.com/page/Single_Sign-On_with_SAML_on_Force.com
https://developer.salesforce.com/page/How_to_Implement_Single_Sign-On_with_Force.com

4)Advanced Currency Management

There were few questions on this too .make sure you understand multicurrency and related reporting

5)LDV(Large Data Volume Handling)

https://developer.salesforce.com/page/Best_Practices_for_Deployments_with_Large_Data_Volumes

6)Sharing Architecture

https://developer.salesforce.com/page/Protecting_Your_Data_in_the_Cloud
https://developer.salesforce.com/page/A_Guide_to_Sharing_Architecture
https://developer.salesforce.com/page/Record-Level_Access:_Under_the_Hood

7)Security Coding Guideline's for Visualforce (Know stuff like XSS and CSRF)

8)Network layer concepts like Firewall,Proxy ,Reverse Proxy ,DMZ

9)Apex Design Patterns 

10)Mobile Application Development Apporach(Design Approach ,when to choose hybrid,Native or Salesforce 1)

11)Understand Governance and Change Management Strategy .Understand Importance of trust.salesforce.com

12)Order of execution of validation rules,triggers ,workflows in a context

13)Optimizing your queries .Search on Youtube you will get number of dreamforce sessions

14)Data loading using BULK API ,increasing throughput and Parallelism .


Hope this article you found helpful and all the best if you are attempting this exam :)

Monday, 28 April 2014

Opportunity_hd Not Found Error


Have a look at above screenshot and it says Opportunity_hd not found while deployment .

The cause of this issue is due to Opportunity History Trending Not Enabled in the Destination Instance .This is a weird error and I am posting so that this may help all who encounter this to resolve themselves 

Business Process and Support Process In Changesets Salesforce

The BusinessProcess metadata type enables you to display different picklist values for users based on their profile. It extends the Metadata metadata type and inherits its fullName field.
Multiple business processes allow you to track separate sales, support, and lead life cycles. A sales, support, lead, or solution process is assigned to a record type. The record type determines the user profiles that are associated with the business process. For more information, see “ Managing Multiple Business Processes ” in the Salesforce online help.

So now the query is how to deploy this Business Process and Support process Via the changesets in SFDC?
If you see the component list you wont see the BusinessProcess in components to Add to the changeset.This is pretty weird as the metadata API for same is exposed in Salesforce .
Mnaually creating hundreds of process in each Instance can be time consuming and Tedious and Using Eclipse or Ant for this for an admin or Business analyst can be a huge exercise and error prone .

So again the same question how to Add these BusinessProcess In Changeset?
The answer is simple .We all have Add Dependency Button in changeset build 
https://help.salesforce.com/HTViewHelpDoc?id=changesets_outbound_dependencies.htm&language=en_US
Here we will discover we have BusinessProcess to Select and Add to the Changeset.Its little weird that it does not appear as Parent Component during change set build .
May the force be with you All :)

Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...