I'm trying to set the 'Rating' field on an account record using the client-side controller. The account record has been returned from the server. Here's my approach.
Application:
<aura:application controller="SetFieldTestCtlr">
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<!--type=Object does not fix the problem-->
<aura:attribute type="Account" name="acc"/>
acc.Name: {!v.acc.Name}<br/>
acc.Rating: {!v.acc.Rating}
</aura:application>
Client-side Controller:
({
init : function(cmp, event, helper) {
console.log('init');
var action = cmp.get('c.getAcc');
action.setCallback(this, function(response) {
var acc = response.getReturnValue();
acc.Rating = 'Hot';
cmp.set('v.acc', acc);
});
$A.enqueueAction(action);
}
})
Server-side controller:
public class SetFieldTestCtlr {
@AuraEnabled
public static Account getAcc() {
return [SELECT Name FROM Account WHERE Id = '0015000001CQpNiAAL'];
}
}
The result is that the 'Result' property value is not rendered:
What I've tried so far:
- Using a getter & setter for the 'Rating' property (doesn't work)
- Querying the 'Rating' field on the server-side controller (this DOES work if the Rating field is non-null)
- Setting the 'acc' attribute's type to 'Object' (doesn't work)
- Setting other properties on the acc object (none of these work)
cmp.set('v.acc.Rating', 'Hot');
cmp.set('v.acc.Rating', 'Hot');
can be used in iteration as well. However, I have updated my answer so it can work with your approach.