Skip to main content

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 method getCelcius that will make the call to our stub class and get the output. if you want to refresh your memory on the stub class, please check out the first post - Part 1.
 Now that we have the controller, lets setup the visualforce page to enter the value and see the output.

Visualforce page
I am not spending time on the basics of how to setup the visualforce page here. So see below the page i setup -

Visualforce code -
Page look and feel based on code above -


As you can see, it is a very basic page. For now, we are going to use only the first button "Convert" which is pointed to my method in the Controller. I will explain the other two buttons in the next post when I explain Asynchronous Apex callouts. You can remove those two buttons from your Visualforce page for now.

Note: Now I didnt really need two methods in this example, I could have just called getCelsius directly from the commandButton Convert. I choose to do it this way as it will help me explain Asynchronous apex callouts easily in the next post. Feel free to point your button to getCelcius method directly.

Thats it, we have created our Visualforce page with the button that is calling our method which calls the webservice stub.

I enabled my Debug logs and clicked the button. The logs clearly showed me how the call was made synchronously -
You will see the actual callout logs being shown in between the System debug lines - "before calling the service" and "after calling the service".

In the next post, we will do the same using Asynchronous Apex callout approach!

Comments

Popular posts from this blog

Workaround to bypass Salesforce SSO

One of the best practices for implementing Single Sign On for your Salesforce org is always ensure there is a way your System administrator can login via the standard login page side-stepping the SSO configuration.  Reason for this is if ever something goes wrong with your Idp provider's service and the SSO authentication responses are not coming as expected, all your users are unable to login. That is, if you have setup your My domain to prevent logins via standard Salesforce login urls (login.salesforce.com). This includes the System administrator as well. Only if your system administrator can somehow login, then he or she can disable the SSO settings for your domain and allow login via the normal login page as a temporary measure. What do you do in such a situation? Well Salesforce has built a workaround for this which is not well documented anywhere (probably for a good reason :) ). I found out about it from a colleague at work. If your my domain url is - https://Com

Salesforce Big Objects - Key learnings

I remember reading about Salesforce Big Objects before they became available and thought maybe it is an option to backup data present in regular objects. That is, instead of taking a backup via an ETL tool or data loader, maybe this will be an option to backup the data in the Force.com platform itself. Now that it is GA and I am reading more about it, i think the use cases for this are more varied. Some use cases I can think of are –  Archival of key data objects within the platform: You may want to use this option if you dont use any other means to backup key data. Also this may be an attractive option for non-large enterprise customers who dont themselves invest on large data warehouses or data lakes in their enterprise architecture. Ex: customer history (if present in tasks and activities) will become huge over years but this is useful information for reporting & customer analysis. Store key information which is large volume in quantity and also high volume in transa

DBAmp for Salesforce - salesforce integration for SQL Server DBAs

Recently i got the opportunity to explore a tool called DBAmp for integration with Salesforce. I found it to be a very useful tool which will help with any data manipulation requirements in Salesforce. Following are my learnings from the exercise. Hope it helps any of you who may need to work with this tool -  DBAmp is a SQL Server package that can be used to integrate with Salesforce. The site where this software is available is - http://www.forceamp.com/ Overview: It essentially installs on top of an existing SQL Server database and provides an OLE DB connector that can be used to connect to Salesforce. Behind the scenes, it executes API calls against Salesforce for any SQL server command it receives. Thus we can create a connection in SQL server to Salesforce org and pull data into tables in the database just as if we are querying against Salesforce tables directly. Use cases for DBAmap + Salesforce: Many use cases exist for using this tool against Salesforce. Pr