Consuming External Web Service in Apex – Salesforce

One of the feature we have in Salesforce is that we can easily consume External Web Services. In this article, we will learn step by step demo of consuming Web Service in Apex. There are many public websites available to consume Web Service and one of them, I am using in this article is http://www.webservicex.net , from this location we are using Stock Quote Webservice. To consume this, we need WSDL.

The Web Services Description Language (WSDL) is an XML-based interface description language that is used for describing the functionality offered by a Web Service.

WSDL have to be downloaded from this location. We need this WSDL in later part of this tutorial.

Once, WSDL is downloaded and saved on local drive. We have to go to Salesforce and navigate to “Setup | Develop | Apex Classes”. On right hand side, you will find button named as “Generate from WSDL”. This button will generate equivalent Apex class to support Webservice call. In some Programming languages, these classes are known as Proxy classes or Stubs.

When we click on “Generate from WSDL” button, it will prompt for WSDL File. Select WSDL file downloaded previously and click on “Parse WSDL” button. On next page you will get this error : “Failed to parse wsdl: Found more than one wsdl:portType. WSDL with multiple portType not supported”.

In some cases you may also get error like : “Failed to parse wsdl: Found more than one wsdl:binding. WSDL with multiple binding not supported”.

Continue reading “Consuming External Web Service in Apex – Salesforce”

Create SOAP message using Java

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags , , with Leave a comment on Create SOAP message using Java

Step by Step Example of creating SOAP Message using core Java API

In this article, i am going to create the SOAP Message by using core Java Only. SOAP Stands for ” Simple Object Access Protocol”, which is used to exchange the structured information via Webservices.

SOAP Message consist of following three parts:

  1. SOAP-ENV:Envelope
  2. SOAP-ENV:Header
  3. SOAP-ENV:Body
SOAP Message Format for Web Services
SOAP Message Format for Web Services

Continue reading “Create SOAP message using Java”

Row expand collapse using jquery and Ajax

Author posted by Jitendra on Posted on under category Categories ASP.NET and tagged as Tags , , , , , with 3 Comments on Row expand collapse using jquery and Ajax

Using JQuery and Ajax to expand and collapse the row in ASP.NET

This article describes how to expand and collapse rows of a GridView or Table and showing data details using Jquery and Ajax

Introduction:

Now day’s , important issue with web applications is how quick a wed page is rendered  and how it is animated or  visualized

So for quick reply from server Ajax is the solutions and for some visualizations with server side response we mostly use jquery or javascript.
I this article, for exp

anding , collapsing and  adding details to gridview row we are going to use AJAX to make call to server and we will visualized it using jquery.

Aim

1. Getting details of product  by extracting details at the next to current row and before second    one.

2. Visualizing  the expanding of rows.

3. No server side postback.

4. Using GridView Control to bind data and simple data binding to table using scriptlet.

Using  Jquery Code

Expanding Row :

For expanding any row, we need to create an new row  with the serverside details  and then we will add it to the next of current row

Ajax JQuery Row Expand Collapse

var trindex=0;	//trindex hold row index created by jquery
$("tr").click(function() {
if ($(this).find("td:first").length > 0) { //check whether it is header or content row
//row index increment to assign new row id everytime
trindex++;
//create a row with td colspan 3 to show product description
var row= '><td class="currRow" colspan="3" ><
div id="did"><img id="imagepath" src=""
style="height: 81px; width: 104px" />  Description :<
span id="des">sd</span><p>Cost :<
span id="cost">sd</span></p></div></td></tr>';

//adding animation to row
var newRow = $("<tr id=tr"+ trindex + row).animate({
height: "140px",
opacity: 0.25,
}, 500);
//adding row to existing table
$(this).after(newRow);
Collapsing  Row :

At the same moment we expand any row, we collapse previous created row, so we need to remember the previous created rowIndex or it’s id.

Ajax JQuery Row Expand Collapse

$("#"+rowName).find('td').removeClass('currRow').addClass('hideRow');
$("#"+rowName).animate({
    height: "0px",
    opacity: 0.25,
    }, 1000, function() {
$("#"+rowName).remove();</pre>
<h5>Ajax Call to the server :</h5>
For getting the full details about our shortly highlighted product, we need to make a asynchronous call to
server using AJAX. We are passing some key values to server(product Id) to extract the resultset.
<pre>$.ajax({
       type: "POST",
       url: "WebService.asmx/GetDetails",   //webserviceName/methodName
       data: "{'name': '" + $(this).find("td span").text() + "'}",  //passing values to webservice(productid)
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function(msg) {
       //extrating response data to newly created row
       $("#tr"+trindex ).find("td #did p #cost").text(msg.d.id );
       $("#tr"+trindex ).find("td #did  #des").text(msg.d.order);
       $("#tr"+trindex ).find("td #did #imagepath").attr('src', msg.d.order);
//$("#myImage").attr("src", "path/to/newImage.jpg");
       },
       error: FailedMessage     //showing error message if failure
       });
Using The WebService.cs

Programmable application logic accessible via standard Web protocols.We are using webservice to extract data from database using jquery Ajax call.  CollectData class to hold extracted details from db.

public class CollectData
{
        public string cost { get; set; }
        public string imagePath { get; set; }
        public string description { get; set; }
}

Simple queries to the database via WebMethod

[WebMethod()]
    public CollectData GetDetails(string name)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].
        ConnectionString);
        SqlCommand cmd = new SqlCommand("Select cost, imagePath, description from Products where ProductId='" +
        name + "'",con);
        SqlDataReader data;
        CollectData c = new CollectData();
        try
        {
            con.Open();
            data=cmd.ExecuteReader();
            if (data.Read())
            {
                c.cost= data[0].ToString();
                c.imagePath = data[1].ToString();
                c.description = data[2].ToString();
                return c;
            }
            else
            {
                c.cost = "N/A";
                c.imagePath = "N/A";
                c.description = "N/A";
                return c;
            }
        }
        catch (Exception ex)
        {
            c.cost = "N/A";
            c.imagePath = "N/A";
            c.description = "N/A";
            return c;
        }

    }

Conclusion :

We have mixed up Jquery, Ajax, server Control(Gridview ) to get quick and visualized output. Result can be little bit change as per the browsers.

Uploaded on Codeproject

Download Demo Article