You can set a the value of a Lookup field with the Id of the record it references.
For example, if you have a Contact object you can specify a default for the Account lookup, by specifying an Id string for the AccountId field.
<aura:attribute name="newContact" type="Contact"
default="{ 'sobjectType': 'Contact',
'LastName': 'Smith',
'AccountId': '001i000002zxpz1'
}"/>
You could also leave it blank and then set it in your JavaScript before calling to your Apex controller.
<aura:attribute name="newContact" type="Contact"
default="{ 'sobjectType': 'Contact',
'LastName': 'Smith',
'AccountId': ''
}"/>
And, prior to enqueueing the action set the value explicitly.
var con = component.get("v.newContact");
con.AccountId = '001i000002zxpz1';
action.setParams({
con: con
});
Or, you could leave it blank altogether and set it in your Apex controller:
@AuraEnabled
public static Contact createContact(Contact con) {
con.AccountId = '001i000002zxpz1';
insert con;
return con;
}
The problem is XML does not allow the use of unescaped < or > characters. In Apex (which is where Lightning Components gets its type system) arrays and lists are equivalent. We typically use array notation in attribute defs because you do not have to < and >
encode the []. Try this instead:
<aura:attribute name="colorPalette" type="docSampleNamespace.Color[]"/>
Best Answer
As Kris Gray (@GrayJustise) pointed out on Twitter once, Object is a simple Object, and Lightning doesn't know what to do with it, so it does this only safe thing it can: it makes it a String. Instead, use a Map, which tells Lightning that you have a key-value pair in there you're trying to parse:
Note that you should be using JSON-like syntax (e.g. quoting strings, etc). Lightning will try to do the right thing if you specify Map, but most likely will not if you specify Object. Note that this only applies to the
default
attribute. If you are setting the attribute inside of a method (via component.set), it doesn't matter which you use: