I wrote a piece of code to Concatenate certain words but I'm having issues with the code itself. Basically what I'm trying to do is Concatenate a field with "ABC" n times where n = number in another field.
public class AgeCounter {
public static void fillAgeCounter(List<CustomObject__c> records) {
for(CustomObject__c record : records) {
record.Age_Counter__c = 'ABC';
for(Integer i = 1; i < record.ABC__c; i++) {
record.Age_Counter__c = record.Age_Counter__c + ';' + 'ABC';
}
for(Integer i = 1; i < record.XYZ__c; i++) {
record.Age_Counter__c = record.Age_Counter__c + ';' + 'XYZ';
}
}
update records;
}}
This gives me the error: Line: 3, Column: 24 static can only be used on methods of a top level type
Removing static runs the code but no records are updated in the Custom object.
EX: Custom field ABC = 4 and Custom field XYZ = 2
Expected output after running this class: Field Age Counter gets updated as ABC;ABC;ABC;ABC;XYZ;XYZ
new AgeCounter().fillAgeCounter(myrecords);
to invoke an inner class method