#custom-metadata — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #custom-metadata, aggregated by home.social.
-
How to Use Custom Metadata Types in Flow
How do you use Custom Metadata in Screen Flows?
Salesforce Custom Metadata Types (CMDT) are a type of metadata in Salesforce that allow you to define, deploy, and manage application configurations and settings as metadata. Unlike custom objects, the data stored in custom metadata types can be deployed from one Salesforce environment to another using deployment tools like change sets, Salesforce CLI, or packages. This makes them particularly useful for configuration data that needs to be consistent across environments.
Key Features of Custom Metadata Types
1. Metadata Deployment:
• Both the structure (fields, relationships) and the records (data) of custom metadata types can be included in deployments.
• Records are treated as metadata, making them deployable and version-controlled.
2. Declarative Configuration:
• Define fields, relationships, and records directly in the Salesforce UI or using tools like Metadata API and Salesforce CLI.
3. Programmatic Access:
• Accessible through SOQL queries, Apex, and APIs.
• Example: SELECT DeveloperName, FieldName__c FROM Custom_Metadata_Type__mdt
4. Relationships:
• Support for lookups to other custom metadata types and standard objects.
5. Integration with Packages:
• Custom metadata types can be included in managed and unmanaged packages for easy distribution.
🚨 Use case 👇🏼Build a screen flow for a survey where the admin can change the questions and choices without modifying the flow. Let’s say you have a screen flow with survey questions.
By leveraging custom metadata types, you can provide a way for the admin to change the questions and choices without modifying the screen flow.
Here is how you can build your solution:
1. Create a Custom Metadata Type
Navigate to Setup → Custom Metadata Types → New Custom Metadata Type to define the CMDT. Specify the label, object name, and optional description. Like with custom objects, you can define custom fields for your metadata type, such as Question 1, Choice 1, etc. Create Records: Go to the custom metadata type detail page and create records for your configuration. Each record will represent one question in the survey.
2. Build your flow
Get the CMDT in your screen flow and use them in read-only screen components. Loop through screens in your flow and record the answers using a slider. You can even drive the weighted average calculation using the Custom Metadata.
3. Debug, test and deploy
Ensure that your flow runs well. Deploy the CMDT structure and records along with your flow. Remember all these configurations and data are deployable between environments. You don’t need to export and import them.
4. Maintain the CMDT records
Change the CMDT records when you need to modify the survey.
Notice that we have a get inside the loop in this flow. This is not a big concern for several reasons:
- Each screen in the screen flow splits a transaction.
- As the flow builder, you determine how many times the flow will loop through the number of CMDT records.
Conclusion
Salesforce Custom Metadata Types offer a powerful and flexible way to manage application configurations across multiple environments without hardcoding values within your Flows. By utilizing CMDTs, admins and developers can enhance the process of updating and maintaining dynamic data sets like survey questions in Screen Flows, thereby improving adaptability and efficiency. This approach not only saves time but also maintains consistency and reliability across deployments, making it an invaluable tool for any Salesforce implementation.
What are some other ways you leverage CMDT in flow?
Explore related content:
Using Custom Metadata Types in Flows Without Get
How to Use the Action Button Component in Screen Flow
Enhance UX in Flow with Custom LWC Icon Selector
Can You After-Save When You Can Before-Save?
#Apex #API #CMDT #CustomMetadata #Salesforce #ScreenFlow #SOQL #useCase
-
What about making your automations in DEVONthink more dynamic using variable values? Combine smart rules or batch processing with metadata. We show you how this could work. #devonthink #automation #custommetadata #workflow https://buff.ly/4fuQXBg
-
Salesforce’s record-triggered flows have revolutionized the automation landscape, offering a seamless, declarative approach to triggering business processes from record changes. But as every Salesforce professional knows, business requirements fluctuate, and having the agility to turn this automation on or off swiftly is crucial. Enter Custom Metadata Types, a hidden gem that can serve as an on-off switch for your automation. This post will guide you through using Custom Metadata Types within record-triggered flows to control your Salesforce automation.
Understanding Custom Metadata Types
Before diving in, it’s vital to grasp what Custom Metadata Types (CMDTs) are. CMDTs in Salesforce are similar to custom objects, but they store data that informs the behavior of your org’s processes rather than the data about your business. The beauty of CMDTs is that they allow admins and developers to create highly configurable apps that can be updated without altering code or, in our case, adjusting flows directly.
Why Use CMDTs in Record-Triggered Flows? The primary advantage is adaptability. Business rules change, and you might need to pause certain automations during certain events. Instead of deactivating the entire flow (and later remembering to reactivate it), you can use CMDTs to “switch off” the automation. When you’re ready to resume, switch it back on — all without modifying the flow.
How to Implement the On-Off Switch
Now, let’s explore how to set this up step-by-step:
1. Create a Custom Metadata Type:
- Navigate to Setup, and in the Quick Find box, enter “Custom Metadata Types.”
- Click “New Custom Metadata Type” and give it a label, such as “Flow Switch” (Switch__mdt).
- After creating the CMDT, you must add fields the flow will reference. For instance, create a checkbox field called “All Switch”, “Flow1 Switch”, “Flow2 Switch” etc. (All_Switch__c and Flow1_Switch__c)
2. Add Records to the Custom Metadata Type:
- Once your CMDT is set up, it’s time to create a new record. This record acts as the control setting for your flows. In my case, I named this single record Master.
- All Switch will turn on-off all automation while Flow1 Switch will control only Flow number 1.
3. Adjust Your Record-Triggered Flows:
- Here is the new magic: You don’t need to get your CMDT anymore in flow to use it. You can refer to the values by using the correct syntax in your start element formula conditions and formula resources. The preferred method is to add them to the start element entry formula conditions.
- The syntax you need to use here will depend on your CMDT naming and field labels, but it will look very similar to this:
$CustomMetadata.Switch__mdt.Master.All_Switch__c$CustomMetadata.Switch__mdt.Master.Flow1_Switch__c*Please note that Switch_mdt is the label of the CMDT, Master is the label of the single record followed by the field name.
4. Testing Your Setup:
- Thorough testing is crucial. Adjust the CMDT records and observe if the flows behave as expected. They should only proceed when “Is Active” is true and stop when false.
5. Maintenance and Updates:
- When you need to turn a flow on or off, update the checkbox fields in the CMDT record. There’s no need to adjust or deactivate the flows, ensuring your configurations remain intact.
Leveraging Custom Metadata Types to control your record-triggered flows is not just a smart move; it’s a strategic approach to maintain scalable, dynamic, and adaptable Salesforce automation. This method protects the integrity of your flows, reduces the risk of errors during off-and-on transitions, and saves significant admin time. Most importantly, it provides the agility your business needs to adapt to changing requirements with grace and efficiency. So, flip the switch on your record-triggered flows with confidence, knowing that Custom Metadata Types have got you covered!
Recommended offsite reading: Architecting for Flexible Automation Execution
One Big Record-Triggered Flow or Multiple?
Fast Field Updates in Record-Triggered Flows (Winter 22)
Migrate to Flow Best Practices
#Automation #CMDT #Configuration #CustomMetadata #DynamicAutomation #FlowManagement #RecordTriggered #Strategies