Creating Dynamic Fields in Salesforce

Author: Bruce Tollefson Published: March 2, 2021; Modified: March 14, 2022

Not all sales agents work the same way. Not all of them build relationships with clients in a structured way that aligns with each other. However, being able to understand how they work can provide a way to create a structured measure of success.

There are times when an agent may want to create their own attributes for a client. They may want more flexibility to create their own fields and associate those fields with the client. As an admin or business analysis you could tell the agent to put the attributes in a text field and be down with it. Put it in a note or description field and whenever they want to view that information they know to go to that field that they dumped everything into.

1 year later you; realize several agents are doing much better than others. You survey their customers and realize they are able to cultivate stronger relationships with their clients and you would like to replicate that for the rest of the team. After asking the agents you learn they are taking better notes and their is a set of key attributes that they keep track of to keep a strong relationship with those clients.

Instead of reactively identifying those attributes and sifting through a bunch of notes you could have proactively created a dynamic set of fields reportable fields. With that knowledge you could also have a conversation with the whole team to identify which fields are missing on the records that help them succeed.

In order to create a more dynamic set of fields for your agents. Create 2 new objects (I call them Dynamic Value and Dynamic Label) create a master-detail relationship between the 2 and a master detail with the other object you would like to have the agents create their own fields for. In this case we will use Account. The data model will look like so:

Dynamic_Label__c holds what the field label would be with just the name as the attribute for the object:

Dynamic_Value__c is the junction that holds the value and maintains the link between the objects:

On the Account record(can be any object) you can see the value and label for the field in the related list to identify the attributes for the field:

instead of being reactive you can be proactive and create a report to track and view the different labels and values to determine what fields are missing on the record. From a report you can view the number of accounts, the label, and the values associated to the label. This can be done with a custom report type on the dynamic value object.

Lastly to prevent the number of fields from being too large a trigger can limit the fields per person on the account:

trigger DynamicValueTrigger on Dynamic_Value__c (before insert) { Id = UserInfo.getUserId(); //checks if the trigger has 1 record, if greater than 1 then the record was created by something other than the UI if(Trigger.New.size() == 1){ Dynamic_Value__c dv = Trigger.New[0]; Integer = [Select Count() from Dynamic_Value__c where CreatedById = :currentUser and Account__c = :dv.Account__c]; if(dvCount >= 5){ dv.addError('Can only have 5 dynamic values']); } } }

Leave a Reply

Your email address will not be published. Required fields are marked *