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
CoderCoder 

Getting error - Trying to display the search results.

Hi,

 

I'm unable to get the results for the search. I have a custom object i'm storing  the customer details and i'm searching the record based on customer email id. I have written a apex class for that when i click on Save button i'm getting the error message as:

 

Error: Compile Error: SObject constructor must use name=value pairs at line 35 column 27

 

 

public class SearchCustomer { public SearchCustomer(ApexPages.StandardController controller) { } public List<Customer__c> results = new List<Customer__c>(); public List<Customer__c> customers { get; set; } String email; /* ------------ Getter and Setter for Email -------------------- */ public string getEmail() { return email; } public void setEmail(string email) { this.email = email; } public List<Customer__c> search() { customers = new List<Customer__c>(); for(Customer__c c:[SELECT Id,Email__c FROM Customer__c WHERE Email__c =: email]) { customers.add(new Customer__c(c)); } return null; } public List<Customer__c> getresults() { return customers; } /* public class Customer__c { public Customer__c cust { get; set; } public Customer__c(Customer__c c) { cust = c; } }*/ }

 

 

 

 Can any one able to solve this.

 

Thank you.

 

imuinoimuino

I think the problem is that you are creating a new Customer object to add to the list

 customers.add(new Customer__c(c));

but all you need is to add the c var from the for

 customers.add(c[0]);

telbyte10telbyte10

there is problem in search method.

here is the correct search method

 

   public List<Customer__c> search()
{
customers = new List<Customer__c>();
for(Customer__c c:[SELECT Id,Email__c FROM Customer__c WHERE Email__c =: email])
{
customers.add(c);
}
return customers;
}