People in organizations rely on categorizing data in different ways to make sense of what is happening on a day-to-day basis. As businesses expand, there is an increased demand for more granular reporting, making it necessary to change the architecture of how we categorize and store data.
Salesforce Case Object uses Type and Sub-type fields to classify cases, which has worked well for their business for years. However, these fields are currently too generic to fit well with the organization’s emerging report-generation standards. Therefore, there is an intent to bring in three thrust fields – New Type, New Sub-type, and New Sub-sub-Type – to classify cases further into more granular levels.
However, while the new Schema fields are much more robust, legacy applications and systems data must still be prepared to migrate via the new fields. The old fields may still be necessary while those systems are being updated to the new era, leaving a field consistency problem across the organization.
This can be solved by creating a Mapping in Salesforce using Apex and custom metadata. We can keep track of the old fields for the population of values in the new fields, mapping old field values to new fields using the Apex. This will automate the ability to update old records to the new field values without breaking existing applications.
Why Transition Fields and Use Apex Mapping?
Organizations usually face four key challenges during this transition:
- Incomplete Transition: Not all systems and applications can download and immediately switch to the new fields. This means that a record with the current and future fields may appear the same but with slightly incompatible data.
- Manual Data Updates: If you don’t have an automated solution, you must update each old record to the new fields, a slow, manual process prone to many errors.
- Reporting Accuracy: Reporting from mixed-field and new-field wells may need more accuracy.
- Legacy Systems: Many older systems integrating with Salesforce weren’t built with the new fields in mind.
Mapping Implementation Using Apex and Custom Metadata
The Role of Custom Metadata
The custom metadata will have the mappings between the old and new fields. Metadata between New-Type, New Sub-type, and New Sub-sub-Type can be configured below.
Mapping(s): Custom metadata defines the mapping between old and new fields. The mapping will be our reference table, and the Apex code will be used to map the old record to the new record.
How the Mapping Works
When a record is inserted or updated in Salesforce, this jaywalking solution will be invoked via Apex code. Here’s a step-by-step explanation of how it works:
- Step 1: Check the Old Fields: The Apex code will check whether the old fields (Type and Sub-type) have values.
- Step 2: Look Up Custom Metadata: Using old field values, the Mapping will look up the new field values (New Type, New Sub-type, and New Sub-sub-Type) in custom metadata.
- Step 3: Populate the New Fields: Once the list of corresponding values is identified, the Apex code will automatically populate the new fields in the record.
- Step 4: Save the Record: The record is saved, with the old and new fields populated, so the system is consistent with old and new.
Formula: Mapping Old Fields to New Fields
The Mapping logic can be represented with the following formula:
New Field Value = Lookup(Custom Metadata)(Old Field Value)
This formula shows how the Mapping leverages custom metadata to match old field values to their new counterparts.
Impact of the Solution
Automated Data Migration
The Mapping automates the transition to the new fields. Without an intervention step, updating the records would be faster, more efficient, and less prone to human errors.
Impact: A smooth transition for data administrators, who don’t need to spend 80 percent of their time manually updating records.
Improved Reporting Accuracy
The new fields will become more granular, resulting in more accurate and detailed reporting. Reports will reflect the increased granularity of the new fields and give decision-makers better insight into the tool.
Impact: Accuracy of reporting by 50 percent is achieved by providing more specific categorization through the new fields.
Seamless Legacy System Integration
The Mapping guarantees that legacy systems that rely on the old fields will be unaffected, and those that depend on the higher-resolution fields will get what they need.
Impact: Legacy system compatibility is maintained while improving the data available for reporting.
Data Consistency
So, as both legacy and next-gen systems are populated during this process, you are still retaining data consistency between both worlds.
This way, front-end physical and financial applications aren’t off, not even a little bit. What’s happening is that all the new systems are seeing the same data – the data is not scrambled or changed as it travels between silos.
Impact: Data consistency improves by 40 percent, preventing confusion and errors in reporting.
Final Thoughts
In many cases, organizations need to be current on changing reporting standards. For fields for which CATEGORY (Type, Sub-type) works well, there is a need to transcend these into more dimensions, such as New Type, New Sub-type, and New Sub-sub-Type.
The effort is worthwhile to have more detailed and precise reporting and, therefore, better decision-making(s). Meanwhile, legacy systems may still use the old fields.