Constant

Constant resources in Avonni Dynamic Components allow you to define fixed values that can be reused throughout your component. Unlike variables, constants cannot be changed after they are initially defined. This makes them ideal for storing values that should remain consistent, such as configuration settings, default values, or lookup information.

1. Overview

A Constant resource is a named value that is set once and remains unchanged throughout the lifecycle of the Dynamic Component. This provides several benefits:

  • Centralized Configuration: Store important values in a single place, making it easy to update them without searching through multiple components or interactions.

  • Readability: Using a descriptive Constant name (e.g., DEFAULT_COUNTRY_CODE) makes your component configuration more straightforward to understand than using a hardcoded value (e.g., 'US').

  • Maintainability: If a constant value needs to change (e.g., a new default country code), you only need to update it in one place (the Constant resource).

  • Type Safety: Constants have a defined data type (Text, Number, Boolean, etc.), which helps prevent errors.

2. Use Cases

Here are some common scenarios where Constant resources are helpful:

  • Default Values: Provide default values for input fields, filters, or other component settings. Example: A default country code for an address form.

  • Configuration Settings: Store configuration options that control the behavior of your component. Example: A maximum number of records to display in a list.

  • Lookup Values: Define a set of fixed values that can be used in comparisons or calculations. Example: Status codes, category names, error codes.

  • API Endpoints (Careful Consideration): You could store an API endpoint URL as a constant, but be careful if the endpoint might change (e.g., between development, testing, and production environments). Custom Metadata Types or Named Credentials are generally better choices for API endpoints.

  • Boolean Flags: Use Boolean constants to represent fixed states or conditions. Example: IS_DEBUG_MODE (set to true or false).

  • Record Type Ids: Store Record Type Ids.

3. Creating a Constant Resource

To create a Constant resource in your Avonni Dynamic Component:

  1. Open the Resources Panel: Click the Resources button (usually located in the page editor or component panel).

  2. Create a New Resource: Click the button to create a new resource (often a "+" icon or a button labeled "New Resource").

  3. Select "Constant": Choose "Constant" as the resource type.

  4. Configure the Constant:

    • API Name: Enter a unique identifier for the constant. Use a descriptive name that follows a consistent naming convention (e.g., DEFAULT_COUNTRY_CODE, MAX_LIST_ITEMS). This name is how you'll reference the constant in your component. The API name must be unique.

    • Description (Optional): Provide a brief description of the constant's purpose. This is helpful for documentation and maintainability.

    • Data Type: Select the appropriate data type for the constant:

      • Boolean: true or false.

      • Date: A date value (e.g., 2024-07-26).

      • Date/Time: A date and time value (e.g., 2024-07-26T14:30:00Z).

      • Number: A numeric value (integer or decimal).

      • Record: Used to store a reference to a Salesforce record, typically by its ID. You will generally not define all the fields of a record here. Instead, you'll store the record's 15 or 18-character ID.

      • Text: A string of text.

    • Value: Enter the initial and only value for the constant. This value cannot be changed after the constant is created. The value provided must match the data type.

4. Using a Constant Resource

Once you've created a Constant resource, you can easily reference it throughout your Dynamic Component's configuration. You don't need to type a special syntax manually. Instead, you'll select the Constant from a list:

  1. Locate the Property: In the component's properties panel (or within an interaction's settings), find the property where you want to use the Constant value. This might be a filter value, a component's default value, a text field's content, etc.

  2. Select the Resource: Look for a dropdown list, a selection button, or an icon (often a variable/resource icon) next to the property. This indicates that you can choose a dynamic value. Click it.

  3. Choose Your Constant: The available resources (variables and constants) will be displayed. Select your Constant resource from the list. The system will automatically insert the correct reference to the Constant. It's generally displayed between curly braces { }.

Examples:

  • In a Filter: You're configuring a filter on a Data Table. You want to filter by Country. Instead of typing 'US', you click the resource selection button next to the "Value" field, and choose your DEFAULT_COUNTRY_CODE constant from the list.

  • In a Component Property: You're setting the default value of a Text Input component. Instead of typing the default value directly, you click the resource selection button and choose your Constant.

  • Conditional Visibility: If you created a constant named SHOW_ADVANCED_OPTIONS of type Boolean, in a visibility condition, select your Constant directly from the available resources

5. Important Considerations

  • Immutability: Constants cannot be changed after they are created. If you need a value that can change, use a Variable resource instead.

  • Naming Conventions: Use clear and consistent naming conventions for your constants (e.g., all uppercase with underscores: MAX_RECORDS).

  • Data Types: Choose the correct data type for your constant.

  • Alternatives: For sensitive data or values that need to be managed outside of the component (e.g., API keys, environment-specific settings), consider using Custom Metadata Types, Custom Settings, or Named Credentials instead of constants.

In Summary

Constant resources in Avonni Dynamic Components offer a way to manage fixed values efficiently, contributing to more organized, readable, and maintainable components. Use them for defaults, configurations, and values that should not change during the component's lifecycle.

Last updated

Was this helpful?