I was playing around with Lightning Trail Head Examples and couldn't figure out how to update a record. When I asked google Yoda master, master referred me here,to this post. I was able to replicate this for 'Account' but not for 'Lead'. I checked my console logs, I see there was an error related to loading script(console log error : because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension: 'unsafe-inline' 'unsafe-eval' https://ssl.gstatic.com/accessibility/"). I'm not trying to load any scripts, I'm simply minding my business with Lead.
I followed each and every step as it is (basically copy pasted and changed it to Lead SObject, posting the code as well.) and I still get nothing. please shed some wisdom of light here.
I really appreciate you taking time to reply :)
my component
<aura:component controller="leadController" implements="forceCommunity:availableForAllPageTypes">
<aura:handler name="init" value="{!this}" action="{!c.init}"/>
<aura:attribute name="lead" type="Lead" />
<h1>Test</h1>
<form>
<ui:inputText aura:id="client"
label="{!$ObjectType.Lead.fields.Name.Label}"
class="form-control"
value="{!v.lead.Name}"
placeholder="Name"
/>
<br />
<ui:button class="form-control" aura:id="button" label="Save" press="{!c.save}"/>
<br />
<br />
</form>
</aura:component>
my client- side controller:
({
init : function(component, event, helper) {
console.log('init');
var action2 = component.get("c.getLead");
action2.setCallback(this, function(response) {
console.log(response.getReturnValue());
component.set("v.lead", response.getReturnValue());
});
$A.enqueueAction(action2);
},
save : function(component, event, helper) {
console.log('save:1');
var action = component.get("c.saveLead");
var lead = component.get("v.lead");
action.setParams({
"lead": lead}
);
action.setCallback(this, function() { console.log('SAVED.'); } );
$A.enqueueAction(action);
console.log('save:end');
},
})
my apex controller :
public with sharing class leadController {
@AuraEnabled
public static Lead getLead(){
return (Lead) Database.query( ' SELECT Name FROM Lead LIMIT 1 ' )[0];
}
@AuraEnabled
public static Lead saveLead(Lead lead){
upsert lead;
return lead;
}
}