You need to sign in to do that
Don't have an account?
Samrendra 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;
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;
Looks like you posted wrong code here,beacause I am able to execute the above code without any errors.
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