/*******APP CODE ******/
<aura:application >
<c:AccountDisplayComponent />
</aura:application>
/*******COMPONENT CODE *********/
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="AccControllerClass">
<aura:handler name="init" action="{!c.getResults}" value="{!this}" />
<aura:attribute name="strAccountName" type="Account" default="{'sobjectType':'Account',
'Name':''}"/>
<div class="Text">
<ui:inputText aura:id="AccountId" label="Account Name" />
</div>
<div>
<ui:Button label="Click Me!" press="{!c.getResults}"/>
</div>
</aura:component>
/********JAVASCRIPT CONTROLLER ***********/
({
getResults : function(component, event) {
var newAccount= component.find("AccountId").get("v.value");
var action= component.get("c.saveAccount");
alert(''+newAccount);
alert(''+action);
alert(action.getState());
action.setParams({
"acc" :newAccount
});
action.setCallback(this,
function(response){
component.set("v.strAccountName",response.getReturnValue());
alert(response.getReturnValue());
alert('Hello');
var name = response.getReturnValue();
alert(name);
var state = response.getState();
alert(state);
if (state == "SUCCESS" || response.getState() == "ERROR") {
var name = response.getReturnValue();
alert(name);
alert(action.getReturnValue());
console.log(action.getReturnValue());
alert("hello from here"+name);
}
});
$A.enqueueAction(action);
}
})
/*** APEX CONTROLLER **********/
public with sharing class AccControllerClass {
@AuraEnabled
public static Account saveAccount(Account acc){
System.debug('@@acc'+acc);
List<Account> listAccount =new List<Account>();
listAccount.add(acc);
insert listAccount;
return acc;
}
}