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
DanSadDanSad 

Mass update using fieldsets

I want to write a batch to take all the values in a given fieldset, and overwrite them with another fieldset.

 

In our account object, we have added many fields: several fields for each month of the current, next, and previous year.

Examples: JAN_CURYEAR_Volume__c, FEB_CURYEAR_Volume__c, MAR_PREVYEAR_Revenue__c etc. 

 

Fieldsets are used to group by year. Examples: CURYEAR_Revenue, PREVYEAR_Revenue, CURYEAR_Volume etc.

A given index will point to the same month in any fieldset. 

 

So I'd like to be able to overwrite PREVYEAR_Volume with CURYEAR_Volume, and so on. 

But I'm not sure how to write the iterator, or if I should use an iterator at all!

What's the best way?

 

Thanks board members!

DS

 

 

KevinPKevinP
Well, you can itterate over the fieldset with this bit of code:

Foreach(Schema.FieldSetMember field: SObjectType.Merchandise__c.FieldSets.Dimensions.getFields()){
 // each iteration will be one of the fields. Note that you'll to customize the foreach
// line to  customize it to your fieldset. 
}

If You have any say in it, perhaps you can name your fields in a sane way such that you can parse the field label and map it back and forth.