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
    Feb 15 '16 at 6:00
  • yes but i have another error Feb 15 '16 at 6:29
  • What is the error.
    – Ratan Paul
    Feb 15 '16 at 6:30
  • Invalid selectOptions found. Use SelectOption type in Apex. Feb 15 '16 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
    Feb 15 '16 at 6:33
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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