Newer Version Available

This content describes an older version of this product. View Latest

Custom Apex Class Types

An attribute can have a type corresponding to an Apex class. For example, this is an attribute for a custom Color Apex class:

1<aura:attribute name="color" type="docSampleNamespace.Color" />
Component attribute types can be custom Apex classes, and the following standard Apex classes.
  • List
  • Map
To make use of values held in other Apex built-in classes, create a custom Apex class, and copy needed values from instances of the standard class into your custom class.

When an instance of an Apex class is returned from a server-side action, the instance is serialized to JSON by the framework. Only the values of public instance properties and methods annotated with @AuraEnabled are serialized and returned.

The following Apex data types can be serialized from @AuraEnabled properties and methods.
  • Primitive types except for BLOB
  • Object, subject to limitations described above
  • sObject
  • Collections types (List and Map) when they hold elements of a supported type

Custom classes used for component attributes shouldn’t be inner classes or use inheritance. While these Apex language features might work in some situations, there are known issues, and their use is unsupported in all cases.

Note

Using Arrays

If an attribute can contain more than one element, use an array.

This aura:attribute tag shows the syntax for an array of Apex objects:

1<aura:attribute name="colorPalette" type="docSampleNamespace.Color[]" />