+ Start a Discussion
ynrynr 

SF-SOQL issues

Actually to start with, this may or may not be an issue and am lacking knowledge on SOQL. Let me explain you guys about my case: I got two objects in my database, Users and Contact. Users has got information about user records like email addresses Contact has got info about users contact details like contact email addresses. But User.email != Conatct.email, for some of users in my case and this is because some users have updated the email addresses after the registration. And we did not have any triggers which also updates the contact emails. Now we have that in place. My question is to update the older user accounts(before trigger in place) and I can extract the user emails from User object and Contact emails from Conatct object separately. But I want to extract them in one single data file (excel sheet using Apex dataloader)so that I just replace the contact emails with coressponding new email addresses. Need help in how to extract fileds from two objects into a single data file. Please reply....
Best Answer chosen by Admin (Salesforce Developers) 
kerwintangkerwintang

If you have a relationship where User.ContactId = Contact.Id, it is easier. Simply download all User records and get only the 2 fields:  ContactId and Email. Then, upload the extracted csv file into the Contact table, mapping ContactId to Contact.Id and Email to Contact.Email.

 

If you have a relationship where Contact.UserId = User.Id, it is a little trickier:

 

First, download all User records and get only the 2 fields: Id and Email.

Then, download all Contact records and get 3 fields: Id, UserId, and Email.

 

From this point, you can manually map, use excel functions (e.g. VLOOKUP) to map the Contact.UserId to User.Id, or do it this way:

- Open the User csv file in excel and sort it by Id.

- Open the Contact csv file in excel and sort it by UserId.

- if we have a one-to-one mapping and each User must have a Contact, then directly copy the Email column from User to Contact csv file. otherwise, you can easily check it (since both are sorted by User ID) and manually map it.

 

After updating the Contact csv file, simply upload it back to DataLoader.

 

Hope this helps.

 

Best Regards,

Kerwin

All Answers

aalbertaalbert

Since the data is possibly out of sync between Contact.Email and User.Email, how are you going to correlate the two sets of data?

 

Regardless, you could run two Data loader extracts - one for the Contact records and one for the User records. That will result in 2 CSV files. Using Excel, you can create a single workbook (XLS) with two worksheets - one for each CSV file. Then you can use excel formulas to manipulate the data accordingly. Lastly, save the worksheet with the revised data as a seperate CSV file and use the data loader to update it. 

 

 

kerwintangkerwintang

If you have a relationship where User.ContactId = Contact.Id, it is easier. Simply download all User records and get only the 2 fields:  ContactId and Email. Then, upload the extracted csv file into the Contact table, mapping ContactId to Contact.Id and Email to Contact.Email.

 

If you have a relationship where Contact.UserId = User.Id, it is a little trickier:

 

First, download all User records and get only the 2 fields: Id and Email.

Then, download all Contact records and get 3 fields: Id, UserId, and Email.

 

From this point, you can manually map, use excel functions (e.g. VLOOKUP) to map the Contact.UserId to User.Id, or do it this way:

- Open the User csv file in excel and sort it by Id.

- Open the Contact csv file in excel and sort it by UserId.

- if we have a one-to-one mapping and each User must have a Contact, then directly copy the Email column from User to Contact csv file. otherwise, you can easily check it (since both are sorted by User ID) and manually map it.

 

After updating the Contact csv file, simply upload it back to DataLoader.

 

Hope this helps.

 

Best Regards,

Kerwin

This was selected as the best answer
ynrynr
Thanks guys, your replies have helped me a lot.