0

I am trying to concatenate a formula field for my custom object 'dependants' under the account. As it age it can be a value changed on any day so the field would need to be calculated every time it is viewed. I would like this to be on a visualforce PDF page I am creating. I can query the list but I am unsure how to concatenate the field age within a visualforce page extension. The ideal result would be a single line showing:

Age of dependants: 7, 5, 3

Any help would be appreciated thanks.

1

Using the String methods, you can create a comma-separated list:

public String joinAges(SObject[] records) {
    Decimal[] values = new Decimal[0];
    for(Sobject record: records) {
        values.add((Decimal)record.get(someField));
    }
    return String.join(values, ', ');
}

Note, this is a generic function, but you could definitely use other types of values or reference specific fields/objects. You can't really do this generically in Visualforce, but it's easy in Apex Code.

| improve this answer | |
  • I was trying to do the same thing just with string instead of decimal but I get the following: Method does not exist or incorrect signature: [Dependant__c].get(Decimal) – Michael Sep 23 '16 at 5:40
  • Never mind I didn't read your line below, through apex I already knew this was possible but as it is a formula field which could change every day this doesn't answer my question. But if it's not possible I guess there is no better answer. – Michael Sep 23 '16 at 5:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.