0

The user decided the 'Program' field should allow multiple programs. So I created a new field that uses multi pick list. So now I want to loop through and copy the field 'ABC' to the multi pick list option 'ABC'

Do I need to code this or is there a tool?

More Clearly:

There is a book object with a NAME and a GENRE (Action/Horror/Comedy). People have used this for a few months.

One day they realize they want the book object to have MANY genres. A new field is created called GENRES (it is a multi pick list of the collection (Action/Horror/Comedy)to hold these... So now a book can be a Action AND a Comedy.

The problem is. There is already 5000 records that use the old GENRE field.

How do I copy that GENRE field to the new GENRES field for all the records?

does that make sense ?

5
  • specify your question more clearly.
    – Avijit Das
    Commented Apr 28, 2017 at 19:22
  • 1
    For one time data migration use dataloader to export the records to be updated in .csv and edit necessary info in csv and finally upload the data through dataloader Commented Apr 28, 2017 at 19:35
  • The field types are difference (lookup vs. mult pick list). But I will explore the dataloader. I have never used it.
    – punkouter
    Commented Apr 28, 2017 at 20:00
  • A multi pick list is not a suitable replacement for a lookup unless the lookup was not the best choice in the first place. Should be using a junction object to associate multiple child
    – Eric
    Commented Apr 28, 2017 at 20:06
  • the lookup was not the best choice. They did not know at the time they would need multiple programs associated with an event
    – punkouter
    Commented May 1, 2017 at 14:28

2 Answers 2

1

Follow these steps:

  • Open the Dataloader and select the object and export the all the data in .csv format.

  • Now, go to dataloader again, select the update button, then select the same object, when it will ask for field mapping between .csv and SFDC fields,

    • remove the previous SFDC field name GENRE from the mapping.
    • select new field GENRES of SFDC and map with the .csv field GENRE.

Basically, replacing the column names the of the mapping. And finally upload the data.

Refer: Dataloader youtube video for guidance

4
  • 'a02V0000001pLpG' is not a valid Saleforce ID for the type Book
    – punkouter
    Commented May 1, 2017 at 17:23
  • So I may have got it wrong earlier.. The singular object is its own object and that value is a reference... it doesn't have the actual value... make sense?
    – punkouter
    Commented May 1, 2017 at 17:24
  • Then you need to prepare the .csv properly, taking correct reference Id and then map the fields and upload the data Commented May 1, 2017 at 17:26
  • ok.. got it.. I need the __r to get to the object
    – punkouter
    Commented May 2, 2017 at 15:32
1

If I understand correctly and it is a picklist to multi-picklist value copy you need to do, I would use the Developer Console's Execute Anonymous.

The code you would need to execute would be:

Book__c[] books = [select Id, Genre__c from Book__c where Genres__c = null];
for (Book__c book : books) {
    book.Genres__c = book.Genre__c;
}
update books;

Multi-select picklist use a semi-colon as a separator but you don't need to worry about that here as you are only copying in a single value.

If there were a lot more records so that governor limits were hit, you could add say limit 5000 to the query and execute the code multiple times.

7
  • Genre__c is a 'Custom object' with one field that is the name which is 'Program Name' (Text (80)) so that does not work.
    – punkouter
    Commented May 1, 2017 at 16:58
  • how do I say... book.Genres__c = book.Genre__c.Name ?
    – punkouter
    Commented May 1, 2017 at 16:58
  • Invalid foreign key relationship: Book__c.Program__c
    – punkouter
    Commented May 1, 2017 at 17:00
  • Book__c[] books = [select Id, Program__c from Book__c where BookPickList__c = null]; for (Book__c book : books) { book.BookPickList__c = book.Program__c.Name; } update books;
    – punkouter
    Commented May 1, 2017 at 17:00
  • does that make sense ?
    – punkouter
    Commented May 1, 2017 at 17:01

You must log in to answer this question.

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