function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RiyajRiyaj 

How to Select all the Firstname from the Tab?

Hi,
In my applicaton i using Contace tab.. I want select all the Firstname only from here. and also to bind the all the Firstname in asp.net page dropdown list.. When I m trying this task i got error like  "System.QueryException: List has more than 1 row for assignment to SObject"
Can You please solve the problem?

My Apex Class Code : 

global class getUserName{
 
  WebService static Lead getLeadUserName() {
    Lead c = [SELECT FirstName FROM Lead ];
      Lead l= new Lead(FirstName =c.FirstName);
   return l; 
 
  }
}

 



My aspx Code Behind:

 getUserName.getUserNameService getUserNameObj = new getUserName.getUserNameService();
            getUserNameObj.SessionHeaderValue = new getUserName.SessionHeader();
            getUserNameObj.SessionHeaderValue.sessionId = sessionId;
 
            getUserName.Lead getUserNameResponse = getUserNameObj.getLeadUserName();
 
            ddlUserName.Items.Add(getUserNameResponse.FirstName);

 

SFRajSFRaj

Hi,

 

global class getUserName{
 
  WebService static Lead getLeadUserName() {
    List<Lead> leadList = [SELECT FirstName FROM Lead ];

    List<Lead> ll = new List<Lead>();

if(leadList.size() > 0){
    Lead l= new Lead(FirstName =c.FirstName);

    ll.add(l);

}   
   return ll;
 
  }
}

 

Try this.

RiyajRiyaj

I try this Ur code.... But I got error... pls help me to clear the bug...

 

Code

global class getTeacherName{

WebService static Contact getTeacherName() {
List<Contact> contactList = [SELECT FirstName,Password__c FROM Contact WHERE ContactType__c='teacher'];
List<Contact> l1 = new List<Contact>();

if(contactList.size()>0){
Contact l=new Contact(FirstName =contactList.FirstName);
l1.add(l);
}
return l1; 
}
}

 Error


Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Contact> at line 8 column 38 

SFRajSFRaj

Hi,

 

Try this.

 

global class getTeacherName{

WebService static Contact getTeacherName() {
List<Contact> contactList = [SELECT FirstName,Password__c FROM Contact WHERE ContactType__c='teacher'];
List<Contact> l1 = new List<Contact>();

if(contactList.size()>0){


for(Contact c : contactList){

Contact l=new Contact(FirstName =c.FirstName);
l1.add(l);

}
}
return l1;
}
}

RiyajRiyaj

Attempt

 

global class getTeacherName{

WebService static Contact getTeacherName() {

List<Contact> contactList = [SELECT FirstName,Password__c FROM Contact WHERE ContactType__c='teacher'];
List<Contact> l1 = new List<Contact>();

if(contactList.size()>0){

for(Contact c : contactList){
Contact l=new Contact(FirstName =c.FirstName);
l1.add(l);
}
}
return l1;
}
}

 

Error

ErrorError: Compile Error: Return value must be of type: SOBJECT:Contact at line 15 column 1 


SFRajSFRaj

global class getTeacherName{

WebService static List<Contact> getTeacherName(){



List<Contact> contactList = [SELECT FirstName,Password__c FROM Contact WHERE ContactType__c='teacher'];

List<Contact> l1 = new List<Contact>();


if(contactList.size()>0){


for(Contact c : contactList){


Contact l=new Contact(FirstName =c.FirstName);


l1.add(l);

}
}

return l1;


}


}

 

This one

RiyajRiyaj

 

Aspx Code:

getTeacherName.getTeacherNameService getTeacherInfoObj = new getTeacherName.getTeacherNameService();
getTeacherInfoObj.SessionHeaderValue = new getTeacherName.SessionHeader();
getTeacherInfoObj.SessionHeaderValue.sessionId = sessionId;

getTeacherName.Contact getTeacherInfoResponse = getTeacherInfoObj.getTeacherName;
ddlUserName.Items.Add(getTeacherInfoResponse.FirstName);

 

 

Error:

Cannot convert method group 'getTeacherName' to non-delegate type 'SFLeadLookup.getTeacherName.Contact'. Did you intend to invoke the method?

 

1. How to solve this issue?

2. How debud the Apex Code?