• Monir75
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hello,

 

I am trying to implement an example that uses a method called getLeadAddressByEmail,which uses SOQL to look up a lead based on an email address.  The query returns a lead object with only Street, City, State, and PostalCode.  But when I run the program, I get the following error:

 

System.QueryException: List has no rows for assignment to SObject
Class.getLeadInfo.getLeadAddressByEmail: line 4, column 10 External entry point

Source Error:

Line 105:        [return: System.Xml.Serialization.XmlElementAttribute("result", IsNullable=true)]
Line 106:        public Lead getLeadAddressByEmail([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] string LeadEmail) {
Line 107:            object[] results = this.Invoke("getLeadAddressByEmail", new object[] {
Line 108:                        LeadEmail});
Line 109:            return ((Lead)(results[0]));

  

FYI, here's my code:

 

public partial class _Default : System.Web.UI.Page

{

private string _userId = "yyyyy@zzzzzzz.com";

private string _password = "XXXXXXXXXXXXX";

private string _sessionId;

private string _serverUrl;

private string _nextLoginTime;

private string _leadEmail;

protected void Page_Load(object sender, EventArgs e)

{

 

}

protected void cmdSubmit_Click(object sender, EventArgs e)

{

//Confirm Lead Email Exists

_leadEmail = this.txtEmail.Text;

//See if Session ID exists

_sessionId = (string)(Application["_sessionId"].ToString() == null ? Application["_sessionId"] : "");

_serverUrl = (string)(Application["_serverUrl"].ToString() == null ? Application["_serverUrl"] : "");_nextLoginTime = (

string)(Application["_nextLoginTime"].ToString() == null ? Application["_nextLoginTime"] : "01/01/200000:00:00"); if ((!isConnected()))

{

getSessionInfo();

}

//Call getLeadInfo Web Service

getLeadInfoService getLeadInfo = new getLeadInfoService();

getLeadInfo.SessionHeaderValue = new getLeadInfo.SessionHeader();getLeadInfo.SessionHeaderValue.sessionId =

this._sessionId;getLeadInfo.Lead getLeadInfoResponse = default(getLeadInfo.Lead);

getLeadInfoResponse = getLeadInfo.getLeadAddressByEmail(_leadEmail);

this.txtAddress.Text = getLeadInfoResponse.Street.ToString();

this.txtCity.Text = getLeadInfoResponse.City.ToString();

this.txtState.Text = getLeadInfoResponse.State.ToString();

this.txtZip.Text = getLeadInfoResponse.PostalCode.ToString();

}

public bool isConnected()

{

bool functionReturnValue = false; if (!string.IsNullOrEmpty(_sessionId) & _sessionId != null)

{

//if (DateTime.Now.ToString() > _nextLoginTime)

 if (_nextLoginTime.CompareTo(DateTime.Now.ToString()) < 0)

{

functionReturnValue = false;

}

else

{

functionReturnValue = true;

}

}

else {functionReturnValue = false;

}

return functionReturnValue;

}

public void getSessionInfo()

{

sforce.LoginResult lr = default(sforce.LoginResult);sforce.

SforceService ss = new sforce.SforceService();

lr = ss.login(_userId, _password);

_sessionId = lr.sessionId;

Application["_sessionId"] = lr.sessionId;

_serverUrl = lr.serverUrl;

Application["_serverUrl"] = lr.serverUrl;Application["_nextLoginTime"] = DateTime.Now;

}

}

 

Web Service Code:

 

global class getLeadInfo {

    WebService static Lead getLeadAddressByEmail(string LeadEmail) {
    Lead c = [SELECT Street, City, State, PostalCode from Lead WHERE Email = :LeadEmail];
    Lead l = new Lead(Street = c.Street, City = c.City, State = c.State, PostalCode = c.PostalCode);
   
   return l;

  }
}

 

Any help would be greatly appreciated.  Thanks.

 

Monir

 

Hello,

 

I am trying to implement an example that uses a method called getLeadAddressByEmail,which uses SOQL to look up a lead based on an email address.  The query returns a lead object with only Street, City, State, and PostalCode.  But when I run the program, I get the following error:

 

System.QueryException: List has no rows for assignment to SObject
Class.getLeadInfo.getLeadAddressByEmail: line 4, column 10 External entry point

Source Error:

Line 105:        [return: System.Xml.Serialization.XmlElementAttribute("result", IsNullable=true)]
Line 106:        public Lead getLeadAddressByEmail([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] string LeadEmail) {
Line 107:            object[] results = this.Invoke("getLeadAddressByEmail", new object[] {
Line 108:                        LeadEmail});
Line 109:            return ((Lead)(results[0]));

  

FYI, here's my code:

 

public partial class _Default : System.Web.UI.Page

{

private string _userId = "yyyyy@zzzzzzz.com";

private string _password = "XXXXXXXXXXXXX";

private string _sessionId;

private string _serverUrl;

private string _nextLoginTime;

private string _leadEmail;

protected void Page_Load(object sender, EventArgs e)

{

 

}

protected void cmdSubmit_Click(object sender, EventArgs e)

{

//Confirm Lead Email Exists

_leadEmail = this.txtEmail.Text;

//See if Session ID exists

_sessionId = (string)(Application["_sessionId"].ToString() == null ? Application["_sessionId"] : "");

_serverUrl = (string)(Application["_serverUrl"].ToString() == null ? Application["_serverUrl"] : "");_nextLoginTime = (

string)(Application["_nextLoginTime"].ToString() == null ? Application["_nextLoginTime"] : "01/01/200000:00:00"); if ((!isConnected()))

{

getSessionInfo();

}

//Call getLeadInfo Web Service

getLeadInfoService getLeadInfo = new getLeadInfoService();

getLeadInfo.SessionHeaderValue = new getLeadInfo.SessionHeader();getLeadInfo.SessionHeaderValue.sessionId =

this._sessionId;getLeadInfo.Lead getLeadInfoResponse = default(getLeadInfo.Lead);

getLeadInfoResponse = getLeadInfo.getLeadAddressByEmail(_leadEmail);

this.txtAddress.Text = getLeadInfoResponse.Street.ToString();

this.txtCity.Text = getLeadInfoResponse.City.ToString();

this.txtState.Text = getLeadInfoResponse.State.ToString();

this.txtZip.Text = getLeadInfoResponse.PostalCode.ToString();

}

public bool isConnected()

{

bool functionReturnValue = false; if (!string.IsNullOrEmpty(_sessionId) & _sessionId != null)

{

//if (DateTime.Now.ToString() > _nextLoginTime)

 if (_nextLoginTime.CompareTo(DateTime.Now.ToString()) < 0)

{

functionReturnValue = false;

}

else

{

functionReturnValue = true;

}

}

else {functionReturnValue = false;

}

return functionReturnValue;

}

public void getSessionInfo()

{

sforce.LoginResult lr = default(sforce.LoginResult);sforce.

SforceService ss = new sforce.SforceService();

lr = ss.login(_userId, _password);

_sessionId = lr.sessionId;

Application["_sessionId"] = lr.sessionId;

_serverUrl = lr.serverUrl;

Application["_serverUrl"] = lr.serverUrl;Application["_nextLoginTime"] = DateTime.Now;

}

}

 

Web Service Code:

 

global class getLeadInfo {

    WebService static Lead getLeadAddressByEmail(string LeadEmail) {
    Lead c = [SELECT Street, City, State, PostalCode from Lead WHERE Email = :LeadEmail];
    Lead l = new Lead(Street = c.Street, City = c.City, State = c.State, PostalCode = c.PostalCode);
   
   return l;

  }
}

 

Any help would be greatly appreciated.  Thanks.

 

Monir