2

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+' ' + getEm.name));
     }
     return myStud;
}
7
  • Gelay is My ans making any sense let me know
    – Ratan Paul
    Commented Feb 15, 2016 at 6:00
  • yes but i have another error Commented Feb 15, 2016 at 6:29
  • What is the error.
    – Ratan Paul
    Commented Feb 15, 2016 at 6:30
  • Invalid selectOptions found. Use SelectOption type in Apex. Commented Feb 15, 2016 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 Paul
    Commented Feb 15, 2016 at 6:33

1 Answer 1

7

Error in this line

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

this should be name value pair.

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

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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .