Skip to main content
Trailblazer Community 已在 Slack 正式上线!更快获得解答,与其他 Trailblazer 交流,并向专家学习。加入社区

Create Custom Lightning Types

Learning Objectives

After completing this unit, you’ll be able to:

  • Identify the three main parts of a Lightning type.
  • Explain the benefits of using custom Lightning types.
  • Choose between Apex-based and object-based schemas.
  • Describe the process for creating Lightning types.

Before You Start

Before you start this badge, consider completing this recommended content.

What Are Lightning Types?

Lightning types are JSON-based data types that help you structure, validate, and display data in Salesforce. While Salesforce provides standard Lightning types out of the box, you can also create custom Lightning types to tailor the user interface experience to your specific business needs.

The Three Pillars of Lightning Types

Every Lightning type, whether standard or custom, consists of three essential parts that work together to create a complete UI experience.

  • Schema: Defines the structure of your data and its validation rules. This includes:
    • Data type specifications
    • Format requirements
    • Maximum length constraints
    • Required field designations
  • Editor: Controls the UI for entering or editing information, providing the input experience for users.
  • Renderer: Controls the UI for displaying information as output, managing how data appears to users.

Benefits of Custom Lightning Types

Custom Lightning types provide two significant advantages over standard data types.

Enhanced UI Customization

Gain complete control over the user interface by associating a custom Lightning web component that matches your specific styling and behavior requirements. This ensures your data presentation aligns perfectly with your brand and user experience goals.

Better Handling of Complex Data

Manage and display complex data structures that standard types aren’t designed to support, including deeply nested objects, complex arrays, dynamic fields, and custom validation logic.

Choose Your Schema Approach

The most important decision when creating a Lightning type is choosing between Apex-based and object-based schemas. This choice isn’t just about preference—it is often determined by the Salesforce application or channel where you intend to use the Lightning type.

Apex-Based Approach

Select this approach when you need to reference an existing Apex class to define your data structure. This method is required for Agentforce Employee agents in Lightning Experience and on Mobile as well as Agentforce Service agents via Enhanced Chat v2 and on Mobile.

This approach is powerful because it allows you to leverage existing Apex business logic and handle complex data structures.

Note

The Apex class dropdown doesn’t show file-based Apex classes, but you can manually enter the fully qualified class name if needed.

Object-Based Approach

Select this approach to define a custom schema directly in Setup by specifying individual fields. This method is typically used for Experience Builder sites and Prompt Builder.

This declarative approach is simpler and doesn’t require Apex knowledge, making it ideal for administrators who need to define straightforward JSON object structures without writing code.

The Creation Process

Creating a custom Lightning type involves several key decisions and configuration steps. You start by accessing the Lightning Types setup page through the Quick Find box in Setup. From there, you provide basic information about your type and choose how to define its schema.

Follow these naming conventions and organization best practices when creating custom Lightning types.

  • Use clear, descriptive labels that indicate the type’s purpose.
  • Follow your organization’s API naming standards.
  • Include prefixes if you’re building managed packages.
  • Add a description to document the type’s purpose and use case.

After Creation: Next Steps

Once you create a Lightning type, the configuration path diverges based on your schema choice.

Apex-based custom Lightning types are ready for UI component configuration and field mapping, while object-based types need schema field definitions before you can configure UI components.

Understanding this workflow helps you plan your implementation approach and ensures you’re prepared for the subsequent configuration steps.

You now understand what Lightning types are, how their three core parts of schema, editor, and renderer work together, and how to create a custom Lightning type using an Apex-based or object-based approach. Next, enhance these types with custom UI components and configure how data flows between your schema and components.

Resources

在 Salesforce 帮助中分享 Trailhead 反馈

我们很想听听您使用 Trailhead 的经验——您现在可以随时从 Salesforce 帮助网站访问新的反馈表单。

了解更多 继续分享反馈