Salesforce web service:
global class LeadInfo
{
WebService static List<Lead> GetLeadInfo()
{
List<Lead> Leadinfo = new List<Lead>();
Leadinfo=[SELECT FirstName,LastName,Email from Lead limit 5];
return Leadinfo;
}
}
{
WebService static List<Lead> GetLeadInfo()
{
List<Lead> Leadinfo = new List<Lead>();
Leadinfo=[SELECT FirstName,LastName,Email from Lead limit 5];
return Leadinfo;
}
}
Design a ASP.Net page as just like below:
C# Code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Enterprize;
using LeadInfo_Service;
public partial class Default2 : System.Web.UI.Page
{
private string userid = "anyone@someone.com";// Salesforce user id
private string password = "password"; // password
private string sessionId;
private string serverUrl;
private string leadEmail;
private DateTime nextLoginTime;
protected void Page_Load(object sender, EventArgs e)
{
Panel1.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Application["_sessionId"] == null)
Application["_sessionId"] = "";
if (Application["_serverUrl"] == null)
Application["_serverUrl"] = "";
if (Application["_nextLoginTime"] == null)
Application["_nextLoginTime"] = " #1/1/2000#";
if (!isConnected())
getSessionInfo();
// ' Call getLeadInfo Web Service
Panel1.Visible = true;
LeadInfoService getLeadInfo = new LeadInfoService();
getLeadInfo.SessionHeaderValue = new LeadInfo_Service.SessionHeader();
getLeadInfo.SessionHeaderValue.sessionId = sessionId;
LeadInfo_Service.Lead[] getres = new LeadInfo_Service.Lead[1];
getres = getLeadInfo.GetLeadInfo();
int i;
for (i = 0; i < getres.Length; i++)
{
FirstName.Items.Add((i+1)+")"+getres[i].FirstName);
LastName.Items.Add((i + 1) + ")" + getres[i].LastName);
Email.Items.Add((i + 1) + ")" + getres[i].Email);
}
}
public Boolean isConnected()
{
if (sessionId != "" & sessionId != null)
{
if (DateTime.Now > nextLoginTime)
return false;
else
return true;
}
else
return false;
}
public void getSessionInfo()
{
Enterprize.LoginResult lr;
Enterprize.SforceService ss = new Enterprize.SforceService();
lr = ss.login(userid, password);
sessionId = lr.sessionId;
Application["sessionId"] = lr.sessionId;
serverUrl = lr.serverUrl;
Application["serverUrl"] = lr.serverUrl;
Application["nextLoginTime"] = DateTime.Now;
}
}
No comments:
Post a Comment