Skip to main content

Posts

Showing posts from January, 2016

Salesforce Winter 16 Maintenance exams

Today I passed both of the Winter 16 release certificate maintenance exams - Admin 201 and Developer 401. Actually both of them had almost the same questions so it turned out to be a very quick exercise. As there is always a question around the morality of sharing the actual questions and answers from a test, I am not going to do that. Instead I will try and share information around what you would need to read to be prepared for the test. Based on my experience, there are just a few topics so I think if you go through these, you will be good. The main topics I encountered in the test are - Improvements released to Chatter posts.  There are a couple of important improvements around Chatter to note in Winter 16 release. One of them is the ability to mute posts which will help users cut down the amount of posts they see in the Chatter feed. Another one is the ability to use rich text while creating posts. Improvements to process builder and visual workflows Process builder

Salesforce Lightning Connect to integrate with oData providers

Lightning Connect is a great offering from Salesforce that will allow us to integrate our salesforce org with an external data source which can expose oData rest APIs. The beauty of this integration is that it can be setup with just point and click steps in Salesforce.  The main requirement is that the external data source should expose oDATA services. I will explain what oData is below and then we can talk about the advantages of using this form of integration in Salesforce. oData  According to oData.org , oData is the best way to do REST API integration (there may be others who disagree but we wont go there :) ). As you already know REST APIs expose data in json format from a source and are accessed via unique URI end points. oData enables the creation and consumption of REST APIs identified using URLs and defined in a data model, using simple HTTP messages. It is also called as ODBC for the web sometimes. Following this protocol, it is possible to setup services e

Installing Mongo database on Linux

I was trying to learn basics of using Mongo database recently. I am capturing some of the things I learnt below so it will be helpful for other people. Installing Mongo database on Linux: First lets intall Mongo db. I use a Ubuntu OS laptop. Below are steps to follow to install Mongo - In Linux, it is better to use the package manager to install software. In Ubuntu, we can use the apt commands to install mongo To ensure authenticity of the package that needs to be installed, Ubuntu requires packages be signed with GPG keys. As a first step, let us download the key from ubuntu.com. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927    Next we will need to add the repository for mongo in the list of sources for your ubuntu laptop. I will do that by creating a list file for mongo -   echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list Next keep the

Salesforce - deserialize JSON response in Apex http rest api callout

In my last post - Integrating Salesforce with a HTTP Rest API service , I mentioned I would test out how to take the rest api's json response and convert it to an object using JSON deserialize. If you are interested to see how to make the apex callout, please see the earlier post. Now lets modify the earlier apex call to see how to the json string response received from the api and make an object of it. Once it is a object, we can use it to apply any of our business logic on it. First lets take a response of the json response we are receiving -  As you can see we are receiving back an array of json objects. Each object as three attributes - login, firstname and lastname. Now I can create a class in Apex that matches the definition of this json object. This class will be used to convert (deserialize) the json string. I created an inner class "UsersFromApi" which matches the json object and added a constructor for it. Now after I make the API callout

Integrating Salesforce with a HTTP Rest API service

In one of my previous posts, I created a Rest API endpoint using a Spring based java application and deployed it to Heroku. Now that we have an endpoint that returns json output, I would like to create an integration to it from my Salesforce org. If you are interested in how I built the rest api end point, please see below steps - Setting up a Spring rest api web app Deploying my Spring application on Heroku To integrate this in Salesforce, I will create an Apex class to do the callout. The http callout will call the rest api and get the response. For this demo, all i am doing is getting the output and writing it to system debug. But hopefully this will show how the same can be done in a real business usecase. First lets add the API endpoint url as a remote site. This will tell Salesforce that this is a valid endpoint to call. This is done in Setup -> Security Controls -> Remote Site Settings. Now that the site is added, lets create the Apex callout class. I a

Java - working with Threads

In one of my last posts, i created a Spring based rest api project and hosted it on Heroku . If you would like to read about it, please see below posts - Setting up a Spring rest api web app Deploying my Spring application on Heroku I was working on a similar project at work where I was using Siebel java databean to create a rest api interface into our Siebel application. I wanted to test the performance of this application. This was more of a quick unit test and I decided to do this by running a Java application with multiple threads calling the API at the same time. I am posting below the sample program to show how I did it. It is a very basic tutorial giving an example of using threads in Java. It also shows how to make HTTP calls from a java application. First I will setup a class that will make my HTTP call to the Heroku api I setup - As you can see in the above class, I am implementing the Runnable interface with it. This is the interface that will help me ru

Deploying your Spring MVC java application on Heroku

In one of my previous posts, we setup a local rest api web application with a spring data jpa, hibernate and a postgreSQL database. That post was Rest Api with Spring, hibernate and Postgres . The aim for setting up that project was to use it to test out REST http integration from Salesforce. However Salesforce cannot integrate with a local service. So we need to deploy this service to an externally exposed server. I decided to expose it on Heroku. Heroku is a platform as a service cloud provider. You can create your application and deploy it to their platform. They take care of managing the actual server where the application is deployed. Moreover its all on the cloud. You just login to their portal and manage your application. Your source code for the application is maintained in Git. You can made changes in Git and deploy it back to Heroku. Internally it deploys your app to linux servers (they called dynos). If you need to scale your app for heavy traffice, you can increase t

Apex Future methods

In the last three posts, we examined calling a webservice from a visualforce page's controller. We explored calling them as synchronous apex callouts and asynchronous apex callout (Continuation pattern) - Integrating Salesforce with SOAP webservice - Apex callout Integrating Salesforce with SOAP webservice - Apex callout part 2 Asynchronous Apex Callouts - Continuation  Now lets explore one more way to call Apex asynchronously. Future methods are used in Apex to execute their logic in a separate thread than the main thread. This is very useful in moving a long running Apex callout into a asynchronous mode execution. So in our example, if we want to take a value from the user and convert it to Celcius by calling the webservice but dont need the user to wait for the result, we can use a future apex method. The user will be free to proceed with other work as the callout happens in a different thread completely. That thread will receive the results of the callout and proc

Asynchronous Apex webservice callout - Continuation pattern

In my last two posts, we went through a basic example of consuming an external web service in Salesforce to generate a stub class and then using that stub class to call the webservice from a visualforce page controller. Integrating Salesforce with SOAP webservice - Apex callout Integrating Salesforce with SOAP webservice - Apex callout part 2 In the above example, our callout was synchronous. The user as well as our code (system resources) are going to wait for the webservice to reply and our code to process the response prior to be able to do anything else. If the external webservice responds within 1-2 seconds, no harm done. This should be fine. However there are chances you will encounter webservices in business scenarios that will take longer to respond. This may be because they have to do a significant amount of work prior to responding back to Salesforce. Maybe they process huge number of transactions and during peak loads, their response is slower. All possible scenar

Integrating Salesforce with SOAP web service - Apex callout Part 2

In my last post, we went through setting up the stub classes in Salesforce by importing the wsdl for the webservice - Integrating Salesforce with Soap web service Part 1 . Now lets complete the use case I started with. I wanted to build a visualforce page with an input field to enter a fahrenheit value and click a button which will call the webservice and get back the Celcius value. This celcius output will be shown in a output field on the page. All very basic but I will use this basic example to walk through the approaches in Salesforce for Apex webservice callouts. You can pick up the concept and implement your real world business use case accordingly. Controller with the synchronous apex callout So lets setup the Controller class that I will use for my Visualforce page first. As you can see it is a very simple Controller class. There are two properties for holding the celcius and fahrenheit string values There is a method callNormalMethod which in turn calls the

Integrating Salesforce with a SOAP web service - Apex callouts

In today' world most APIs and integrations are REST, however sometimes you will encounter a need to integration with SOAP web services. Recently I encountered this in my project where we had to integrate Salesforce with a legacy system that could expose only SOAP web services. There were couple of options for us - 1. Create a rest API service that would play an intermediary role between Salesforce and the soap web service from the external system. Salesforce would consume the rest API to communicate with it. 2. Use a middleware to do the above for us. 3. Integrate Salesforce with the SOAP service directly. In our situation, we ended up taking option 3. Now, I am not discussing the merits of using a middleware tool here, so lets not get into why we choose option 3. Instead lets focus on learning how simple and easy it is to integrate Salesforce with a SOAP web service. For our learning experience today, i will use a web service freely available on the internet - http://