0

I want to imports 1200 contacts in existing 1200 household accounts, i have their ids but i am unable to import them. I tried importing them through import account and contacts but i was unable to do so.

Dataloader is not working. please suggest some solution other then dataloader. Any help is very much appreciated.

3
  • What errors are you seeing? Mar 18, 2015 at 13:15
  • there are no errors as such, i am able to insert contacts to accounts while i am mapping them via name but the problem is that i have many duplicate account name. And while i am trying using id it is wanting me to add contact id as well which is not available as i am creating new records. I also entered dummy id in contact but the records were not inserted. Mar 18, 2015 at 13:20
  • When you insert Contacts, you will not need Contact Ids. Maybe you were trying to upsert? Or you are confusing Account Id with Contact Id. Mar 18, 2015 at 13:49

1 Answer 1

1

If you are familiar with Apex, this will be super easy : :

List<Account> accounts = [Select id, FirstName, LastName from Account];


List<Contact> newContacts = List<Contact>();


for(Account account : accounts) {

    // Tie the account to the contact.
    Contact c = new Contact(Account__c = account.id, FirstName =    account.FirstName, lastName = account.LastName);
    newContacts.add(c); 

}

insert newContacts;

for(Contact c : newContacts) {

    for(Account a : accounts) {

       if(a.id = c.Account__c) {

           a.Contact__c = c.id;

       }

    } 
}

update accounts;

This would create new contacts for every account that exists, then it will assign the account to the contact. Once the account is assigned to the contact, the contacts will be inserted into the database.

After that, we will tie the contact back to the account by iterating through the new contacts and applying their ids to the appropriate accounts, then update the accounts.

If you are not familiar with Apex, I strongly recommend reading up. It makes large tasks like this super easy! Check out http://www.salesforce.com/us/developer/docs/apexcode/ to get started!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .