Salesforce connect - can't add new record
Posted: Thu 24 Oct 2019 02:50
Dear All
I've installed the ADO.NET Provider for Salesforce in Visual Studio 2017 and 2019.
I can connect to my developer salesforce org no problems in server explorer. I can also create create an ADO.NET Entity Data Model using EF5 no problems and connect to it in a console application and read contents of tables.
I can't however add new records in my c# console application;
var db = new Entities1();
var contacts = db.Contacts;
var model = new Contact();
model.FirstName = "Bill";
model.LastName = "Bloggs";
model.Name = "Bill Bloggs";
model.OwnerId = "xxxxxxx";
model.Gender = "Male";
contacts.Add(model);
db.SaveChanges();
The code fails on the final line with a entity validation error of "The Id field is required.". Happens in both VS 2017 and 2019.
I understand this field to be the primary key, ready only and I guess it would normally be created within Salesforce itself so its unclear to me how to handle this.
I did create an edml instead of the edmx to see if that offered a solution using EF6. But my code can't open it - fails with a message about the username, password or token being incorrect even though they are not because they were used to create the edml successfully in the first place.
I'm really keen to find a solution to this since my ability to successfully add data would mean that I can port our entire database to Salesforce (200+ tables) which is the objective.
Thanks, Phil
I've installed the ADO.NET Provider for Salesforce in Visual Studio 2017 and 2019.
I can connect to my developer salesforce org no problems in server explorer. I can also create create an ADO.NET Entity Data Model using EF5 no problems and connect to it in a console application and read contents of tables.
I can't however add new records in my c# console application;
var db = new Entities1();
var contacts = db.Contacts;
var model = new Contact();
model.FirstName = "Bill";
model.LastName = "Bloggs";
model.Name = "Bill Bloggs";
model.OwnerId = "xxxxxxx";
model.Gender = "Male";
contacts.Add(model);
db.SaveChanges();
The code fails on the final line with a entity validation error of "The Id field is required.". Happens in both VS 2017 and 2019.
I understand this field to be the primary key, ready only and I guess it would normally be created within Salesforce itself so its unclear to me how to handle this.
I did create an edml instead of the edmx to see if that offered a solution using EF6. But my code can't open it - fails with a message about the username, password or token being incorrect even though they are not because they were used to create the edml successfully in the first place.
I'm really keen to find a solution to this since my ability to successfully add data would mean that I can port our entire database to Salesforce (200+ tables) which is the objective.
Thanks, Phil