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
TheCustomCloudTheCustomCloud 

For Loop question

I am cloning a record and then using a for loop to change say half of the fields on the cloned record.  Then I am updating the object.  I dont want to write a line for every field I am updating so I wrote a for loop.  Unfortunately, its not working.

 

public void setupMergedAccount(){
        mergedAccount = toAccountObj.Clone();
        List<String> fieldsToChange = new List<String>{'Phone','BillingCity'};
        for(String f : fieldsToChange){
            mergedAccount.[f] = fromAccountObj.[f]; // USING THE VARIABLE HERE DOESNT WORK 
        }
}

 

Anyone?

 

 

iBr0theriBr0ther

I can suggest:

 

public void setupMergedAccount(){
        mergedAccount = toAccountObj.Clone();
        List<String> fieldsToChange = new List<String>{'Phone','BillingCity'};
        for(String f : fieldsToChange){
            mergedAccount.put(f, fromAccountObj.get(f) );
        }
}

 

Cheers,