1

How can I, for each "type" of CASE, (Selected from a dropdown) show specific "FIELDS" for the agent to enter data?

The idea is that in SF ADMIN we could (for each case type) configure a SET of fields that the Agent should capture so that Back Office teams can do their work later.

One example would be a CASE related to request fund TRANSFER (for large amounts). For this CASE TYPE we would store something like this in Salesforce ADMIN (A configuration, done once per CASE TYPE):

{
    version : 1.1
    destination-account={
        required : true
        default : null
        label: “Destination Account”
        type: TEXT
        validation: [regex]
        visible : true
    }
    transfer-amount= {
        required : true
        default : null
        label: “Amount to be transferred”
        type: MONEY
        validation: [regex]
        visible : true
    }
    currency = {
        required : true
        default : "USD"
        label: “Currency”
        type: TEXT
        validation: [regex]
        visible : false
       }
    }

Once the case is created, APEX would read the fields and add them as JSON into a CUSTOM TEXT FIELD (named something like "EXTRA INFORMATION") in CASE object. APEX code would infer the values from the CASE TYPE configuration (JSON) above that was previously done in the ADMIN. The "EXTRA INFORMATION" field would store something like:

{
    version : 1.1
    destination-account : "afsdfsd-RT2"
    transfer-amount : 10000000
    currency : "USD"
}

So the back office system reading this field (and looking at the VERSION) would know how to parse that data for BACK OFFICE use

Thanks

1 Answer 1

0

Salesforce already has something that does something like this: Record Types. Admins can create record types, define the valid picklist values for them, and assign specific page layouts to determine which fields are visible, editable, and/or required. The only bits left that you'd have to worry about would be the JSON-serializing bits, which might use some Custom Metadata to map field names to property values for JSON storage:

// Assuming this triggers in a before insert/before update scenario
Map<sObjectField, String> propertyMappings = new Map<sObjectField, String>();
for(FieldMapping__mdt fieldMapping: FieldMapping__mdt.getAll().values()) {
  propertyMappings.put(fieldMapping.Field__c, fieldMapping.Name);
}
Map<String, sObjectField> caseFields = sObjectType.Case.fields.getMap();
for(Case caseRecord: Trigger.new) {
  // Ignore audit fields via clone
  Map<String, Object> caseValues = 
    caseRecord.clone(true, false, false).getPopulatedFieldsAsMap();
  Map<String, Object> output = new Map<String, Object>();
  for(String fieldName: caseValues.keySet()) {
    sObjectField field = caseFields.get(fieldName);
    String propertyName = propertyMappings.get(field);
    Object fieldValue = caseRecord.get(field);
    output.put(propertyName, value);
  }
  caseRecord.Extra_Information__c = JSON.serialize(output);
}

You can add extra bells and whistles as you desire.

This is a minimum effort solution. You could, as you say, build a completely custom UI with a Lightning Web Component, create other configuration objects, enforce all the rules manually, and so on. That's not the sort of solution we would fully write out for you, as it would require several hundred or possibly even thousands of lines of code, minimum, to fully design. A proper solution would take probably a few days to a few weeks to implement. If you want that level of detail, you'll need to do some research and ask the questions as you proceed. Or hire a consultant to do it for you.

1
  • That will fit the bill pretty well! Thanks so much for the help!
    – jfbaro
    Mar 28, 2023 at 20:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .