Newer Version Available

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

Basic Types

Here are the supported basic type values. Some of these types correspond to the wrapper objects for primitives in Java. Since the framework is written in Java, defaults, such as maximum size for a number, for these basic types are defined by the Java objects that they map to.

type Example Description
Boolean <aura:attribute name="showDetail" type="Boolean" /> Valid values are true or false. To set a default value of true, add default="true".
Date <aura:attribute name="startDate" type="Date" /> A date corresponding to a calendar day in the format yyyy-mm-dd. The hh:mm:ss portion of the date isn’t stored. To include time fields, use DateTime instead.
DateTime <aura:attribute name="lastModifiedDate" type="DateTime" /> A date corresponding to a timestamp. It includes date and time details with millisecond precision.
Decimal <aura:attribute name="totalPrice" type="Decimal" /> Decimal values can contain fractional portions (digits to the right of the decimal). Maps to java.math.BigDecimal.

Decimal is better than Double for maintaining precision for floating-point calculations. It’s preferable for currency fields.

Double <aura:attribute name="widthInchesFractional" type="Double" /> Double values can contain fractional portions. Maps to java.lang.Double. Use Decimal for currency fields instead.
Integer <aura:attribute name="numRecords" type="Integer" /> Integer values can contain numbers with no fractional portion. Maps to java.lang.Integer, which defines its limits, such as maximum size.
Long <aura:attribute name="numSwissBankAccount" type="Long" /> Long values can contain numbers with no fractional portion. Maps to java.lang.Long, which defines its limits, such as maximum size.

Use this data type when you need a range of values wider than those provided by Integer.

String <aura:attribute name="message" type="String" /> A sequence of characters.

You can use arrays for each of these basic types. For example:

1<aura:attribute name="favoriteColors" type="String[]" default="['red','green','blue']" />

Retrieving Data from an Apex Controller

This example retrieves a string array of favorite colors from an Apex controller.

This component is bound to the AttributeTypes Apex controller and retrieves the string array when the Update button is clicked. The colors are displayed using a favoriteColors attribute.
1<aura:component controller="AttributeTypes">
2    <aura:attribute name="favoriteColors" type="String[]" default="['cyan', 'yellow', 'magenta']"/>
3    <aura:iteration items="{!v.favoriteColors}" var="s">
4        <p>{!s}</p>
5    </aura:iteration>
6    <lightning:button onclick="{!c.getString}" label="Update"/>
7</aura:component>
The Apex controller has a getStringArray() method that returns a String[].
1public class AttributeTypes {
2    
3 @AuraEnabled
4    public static String[] getStringArray() {
5        String[] arrayItems = new String[]{ 'red', 'green', 'blue' };
6        return arrayItems;
7    }
8
9}
The component’s client-side controller retrieves the string array from the Apex controller by calling getStringArray(). The controller then sets the result in the favoriteColors attribute, which is refreshed in the UI.
1({
2    getString : function(component, event) {
3    var action = component.get("c.getStringArray");
4     action.setCallback(this, function(response) {
5            var state = response.getState();
6            if (state === "SUCCESS") {
7                var stringItems = response.getReturnValue();
8                component.set("v.favoriteColors", stringItems);
9            }
10        });
11        $A.enqueueAction(action);
12    }
13})

To retrieve data from an object that’s returned by an Apex controller, create an attribute with a type corresponding to a standard or custom object.

1<aura:attribute name="accounts" type="Account[]"/>

You can access a field on the object using the {!account.fieldName} syntax. For more information, see Using Apex to Work with Salesforce Records.

The return value from Apex is serialized if it contains a decimal value. If the decimal value has more than 15 digits of precision, the value is serialized as a JSON string to preserve exact precision. Otherwise, the value is serialized as a JSON number literal. This serialization prevents precision loss for high-precision decimal values that exceed JavaScript's double precision limits. You can handle these values as strings in JavaScript and convert the values as needed.

Note