0

I'm working with about 80 strings that look something like the following:

Model #: model_number__c Make #: make_numer__c Character Code: character_code__c

The end goal is to get these strings into a text area that dynamically populates the field API values with actual record data.

What is an effective way to dynamically populate those API names with their data value based on the record that is queried?

5
  • 4
    Is there a reason why you're not using a formula field to do this? – Derek F Jul 10 '20 at 17:15
  • Formula Character limits, I can break it down into multiple formulas but then I run across another issue so I need to take a different approach – ebar Jul 10 '20 at 17:59
  • 1
    Quick Text maybe? Is this a custom textarea? Where are you saving the interpolated strings? I think we need a little more information about your use case. – adriancg Jul 10 '20 at 18:02
  • @adriancg There is an object called machine which is where this information needs to be stored. The strings are in metadata recods called machine descriptions. – ebar Jul 10 '20 at 18:10
  • I'm going to try the route of using getPopulatedFieldsAsMap(); – ebar Jul 10 '20 at 18:23
0

Since your requirements aren't described in detail and there's no code to infer from, one option would be to populate the text area field on the record using a trigger and the string.format(string, parameters) method to create the data that will be placed in the field during insert and update operations.

trigger MachineTrigger on Machine__c(before insert, before update) {
    String template = 'Model #: {0}  Make #: {1} Character Code: {2}';

    for (Machine__c m : Trigger.new) {
        m.YourLongTextField__c = string.format(
            template,
            new List<String>{ m.model_number__c, m.make_numer__c, m.character_code__c }
        );
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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