0

I have a use case where I need to do a one-time data update for around 1.8 Million records. I know that we can achieve this with a data loader or we can create an Apex Batch to achieve this.

Challenge in Data Loader,

I have to update a field with other fields substring from the same object,

List<ObjectA> lstObject = [SELECT Id, Field1, Field2 FROM ObjectA];

List<ObjectA> lstObjectUpdate = new List<ObjectA>();
for(ObjectA ob : lstObject) {
    ob.Field1 = Id.ValueOf(ob.Field2.substring(0, 18));
    lstObjectUpdate.add(ob);
}

if(lstObjectUpdate.size()>0) {
    update lstObjectUpdate;
}

I don't think we can achieve this in using Data Loader.

Challenge in Batch Apex

Actually we don't have any challenge, but we don't have to write a batch for one-time data update.

Is there any other way I can achieve this in the Production environment?

2
  • Why not just use a formula field (instead of the field you are trying to update)?
    – arut
    Aug 8, 2020 at 14:38
  • No we can’t use it, because actually the field is the Master detail field. Aug 8, 2020 at 16:13

1 Answer 1

2

This is easily achieved in Data Loader or any other ETL tool.

Extract the records, modify the data using Excel, LibreOffice, or your editor of choice, and reload it as an update. Ensure that you include the Id column to make this possible.

If the source field only contains a Salesforce Id, there's no need for the edit step. Just extract the data and perform an update, remapping the column for the old field to the desired new friend.

1
  • Yes, that's too easy with Excel to substring the value to make a new field value. Aug 10, 2020 at 6:09

You must log in to answer this question.

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