Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a custom object. this is the error Compile Error: SObject constructor must use name=value pairs at line 8 column 22

    public list<student__c> myStud = new list<student__c>();
   List<student__c> stud_qry = new List<student__c>();
    public list<student__c> stud(){
        stud_qry =  [select Id, First_Name__c, name from Student__c];  
       for(student__c getEm : stud_qry){
          myStud.add(new student__c(getEm.first_name__c+' ' +;
           return myStud;
share|improve this question
Gelay is My ans making any sense let me know – Ratan Feb 15 at 6:00
yes but i have another error – gelay Feb 15 at 6:29
What is the error. – Ratan Feb 15 at 6:30
Invalid selectOptions found. Use SelectOption type in Apex. – gelay Feb 15 at 6:30
Pls don't update this ans instead ask another question else evryone think my ans is different and they will give me downvote – Ratan Feb 15 at 6:33
up vote 6 down vote accepted

Error in this line

myStud.add(new student__c(getEm.first_name__c+' ' +;

this should be name value pair.

myStud.add(new student__c(Name = getEm.first_name__c+' ' +;

You need to specify Field API name and respective value like this Name = getEm.first_name__c+' ' +

share|improve this answer
thank you @Ratan – gelay Feb 15 at 8:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.