function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vance KesslerVance Kessler 

Change from single field to a Lookup without loosing existing values

The business has decided to change what used to require a reference to a single text value to now require a list of text values.  We currently hold the value in a single field but will need to create a new table with a master/detail relationship to hold the list of values moving forward.

My question is how do I change the field type and create this table withoug loosing the existing data?  I know I can create the table and a new field before I get rid of the existing field, but I am not sure how to get the data into the new table. 

This would be a trivial INSERT INTO statement in SQL but I am stumped how to do this in SF.  I looked all over for general advice on schema changes and migrating existing data but found nothing.  This CANNOT be a new concept to SF.

Thanks,
Vance
Mathew Andresen 5Mathew Andresen 5
Unless I'm missing something here you just need to create a map that links the ID's of the record and the value of the old object with the new one.

So if the object was an account with id xxx  and the new object was an opportunity the opportunity would be linked to the account by the Id xxx,  then you would pull the value of the field from account xxx and paste it into the field of the opportunity that is linked to account xxx

You wouldn't even have to do this with Apex if you didn't want to, you could do this with the data loader and excel.  You just need the link between the two objects which would be the first object's Id.

Thanks,
Vance KesslerVance Kessler
Sorry, I am very new to Salesforce and its capabilities.

Are you saying I would MANUALLY copy and paste the values?  In the Data Loader process, what are the high level steps invoved there?

I am very much used to how to make schema changes and migrate data using SQL scripts.  I am still trying to figure out how to think SalesForce'ish.
Mathew Andresen 5Mathew Andresen 5
No, I'm definitely not suggesting you do this manually.  If you go to setup / data management / export you can export the details of the object that you want to get the detail out of.  The important parts being the object ID (which is the key like in SQL tables) and of course the data in the field.  Then I believe you could import that data back in to the new object except now the object ID is going to the lookup field, and then the value is going to whereever you need it to.

I'm sure there are other ways to do this as well.  But this is similar to what I did when I needed to upload several thousand wine tastings, and I wanted to connect them to an account and user ID.

I setup an excel template with the correct account ID, and User Id, for relationship fields (plus my other data of course) and then I uploaded it.  

https://developer.salesforce.com/docs/atlas.en-us.workbook.meta/workbook/load_data_intro.htm