You need to sign in to do that
Don't have an account?
Tony Montana
i am trying to add multiple contacts in one single dml using lists into the contact object. this is what i have so far
Account a = new Account(name = 'Microtek Inc');
insert a;
List<Contact> ContactList = new List<Contact>();
for (Integer i = 0; i < 5; i++) {
contactList.add(new Contact
(
accountID = a.id;
FirstName = 'Charles ' + i;
LastName = 'Test Contact' + i;
NT_Login_Name__c = 'testuser' + i;
Management_Level_Type__c = 'Director';
Former_Employee__c = false;
));
List<sObject> objects = new List<sObject>();
objects.addAll((List<sObject>)(contactList));
insert objects;
will above work ?
insert a;
List<Contact> ContactList = new List<Contact>();
for (Integer i = 0; i < 5; i++) {
contactList.add(new Contact
(
accountID = a.id;
FirstName = 'Charles ' + i;
LastName = 'Test Contact' + i;
NT_Login_Name__c = 'testuser' + i;
Management_Level_Type__c = 'Director';
Former_Employee__c = false;
));
List<sObject> objects = new List<sObject>();
objects.addAll((List<sObject>)(contactList));
insert objects;
will above work ?
change the semi colons; to commas , in the new Contact element
and close the ellipse {}
and i would remove the attempt to cast from contact to sObject. Not really needed. But if you were going the other way, then yes. (e.g sObject > Contact)
regards
Andrew
All Answers
change the semi colons; to commas , in the new Contact element
and close the ellipse {}
and i would remove the attempt to cast from contact to sObject. Not really needed. But if you were going the other way, then yes. (e.g sObject > Contact)
regards
Andrew