What is aura:attribute?
An aura:attribute declares a value on an Aura component. Use attributes for inputs, display state and values returned by a server action. In markup, the v value provider reads those attributes; a client-side controller uses component.get and component.set.
<aura:attribute name="heading" type="String"
default="Application summary" />
<h2>{!v.heading}</h2>Attribute parameters and access
| Parameter | What it controls |
|---|---|
| name | The identifier used in markup and controller code. |
| type | How the attribute value is represented and serialized. |
| default | The initial value when none is supplied. |
| required | Whether a value must be supplied when the component is used. |
| access | Component attribute visibility: public, global or private. |
| description | Documentation for developers using the component. |
Public is the default access setting. Private limits access to the defining resource; global is used when the resource must be available across orgs, such as a packaged component intended for other orgs. Attribute access does not replace object, field or record permissions.
Salesforce: control access to Aura resources
Basic types
Common basic types include String, Boolean, Integer, Long, Decimal, Double, Date and DateTime. Use Date for a calendar date and DateTime when a time is part of the value. Salesforce recommends Decimal over Double for currency fields.
<aura:attribute name="isComplete" type="Boolean" default="false" />
<aura:attribute name="documentCount" type="Integer" default="0" />
<aura:attribute name="reviewDate" type="Date" />Salesforce: supported basic attribute types
Collections: arrays, lists, maps and sets
A typed array such as String[] holds values of that type. List represents an ordered collection. Map associates keys with values. Set represents unique values and does not guarantee order. Use square brackets for array, list and set defaults.
<aura:attribute name="documentNames" type="String[]" default="[]" />
<aura:attribute name="items" type="List" default="[]" />
<aura:attribute name="labels" type="Map" default="{}" />
<aura:attribute name="categories" type="Set"
default="['New', 'Review']" />Use a plain JavaScript object to work with an Aura Map. A JavaScript Map instance is not the same thing. Give an empty map a default of {} when your code expects an object rather than null.
Salesforce: collection attribute types
Salesforce records and Apex wrapper types
An attribute can use a standard or custom sObject type, such as Account or Project__c. A custom Apex class can group values returned to the UI. For custom Apex values returned from a server action, use supported public properties with @AuraEnabled and follow Salesforce’s serialization requirements.
<aura:attribute name="account" type="Account" />
<aura:attribute name="accounts" type="Account[]" default="[]" />
<aura:attribute name="viewState" type="Map" default="{}" />Salesforce: custom Apex class types for Aura
Avoid choosing Object as a catch-all without checking server serialization. Salesforce’s type guidance recommends Map for many values represented as plain JavaScript objects. An attribute declaration also does not validate every assignment made by client-side JavaScript.
Salesforce: how Aura attribute types behave on the client and server
Read, update and bind a value
<aura:component>
<aura:attribute name="heading" type="String" default="Review" />
<lightning:input label="Heading" value="{!v.heading}" />
<p>{!v.heading}</p>
<lightning:button label="Reset" onclick="{!c.reset}" />
</aura:component>({
reset: function(component) {
component.set("v.heading", "Review");
var heading = component.get("v.heading");
// Use heading in the component's next action.
}
})Checks before using an attribute in production
- Choose a default that matches what the UI expects before records load.
- Handle empty collections, missing records and failed server actions.
- Validate values again on the server before a consequential update.
- Test permissions as a normal user, not only as an administrator.
- For existing Aura components, make a focused change and test its callers before changing an attribute name or access setting.
Need help applying this to your Salesforce org?
Bring one example of the process or component you want to improve. We can discuss the requirement, the systems involved and the next step toward a scoped approach and estimate.
