+ 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,