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
Samrendra SinghSamrendra Singh 

Line: 4, Column: 5 Invalid constructor syntax, name=value pairs can only be used for SObjects: Contact OK

Hi Guys,

Please help me. I am facing below error for my code

Error:

Line: 4, Column: 5 Invalid constructor syntax, name=value pairs can only be used for SObjects: Contact  OK

Code:


//Create a new contact

List<Contact> conList = new List<Contact> {
    new Contact(FirstName='Nagraj',LastName='B',Department='Finance'),
    new Contact(FirstName='Deepak',LastName='Shivalingappa',Department='Design'),
    new Contact(FirstName='Sachin',LastName='Gotal',Department='PIM'),
    new Contact(FirstName='Rachithra',LastName='R',Department='Automation')     
};
    
// Bulk insert all contacts with one DML call
    
    insert conList;

// List to hold the new contacts to update

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

// Iterate through the list and add a title only
//   if the department is Finance

for(Contact con : conList){
    if(con.Department == 'Finance'){
        con.Title = 'Financial Advisor';
        // Add updated contact sObject to the list.
        listToUpdate.add(con);
    }
}    
// Bulk update all contacts with one DML call
update listToUpdate;
 
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Samrendra,
Looks like you  posted wrong code here,beacause I am able to execute the above code without any errors.
Samrendra SinghSamrendra Singh
Hi Devi,

Thanks for lookin into it.

Code has executed once but all the contact were not created. But, still it is showing the same error.

Many thanks,
Sam
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Contacts created in my org without any error.
Samrendra SinghSamrendra Singh
Not sure what mistake i am doing.