I'm trying below example which is giving ERROR as response. Any idea on how to get the below code execution successfully:

<aura:component controller="ConCreation">
    <aura:attribute name="conInfo" type="Contact" default="{'sObject':'conatct','LastName':''}"/>
      <ui:inputText aura:id="LastName" label="Last Name"

      <ui:inputText aura:id="FirstName" label="First Name"
    <ui:button press="{!c.saveCon}" label="click"/>    

Aura controller:

    saveCon : function(component, event) {
        var con = component.get("v.conInfo");

        var action1 = component.get("c.saveContact");
        "c": con
        action1.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.conInfo", response.getReturnValue());

Aura apex Class:

global with sharing class ConCreation{
    public static string saveContact(contact c){
        if(c != null)
            insert c;
        return c.id;
  • what is the error message? – Tushar Sharma Jan 19 '17 at 10:05
  • What error message are you facing? – Pranay Jaiswal Jan 19 '17 at 10:30
  • I'm getting 'Error' in response of java script controller – Rv1 Jan 19 '17 at 10:47

You should replace sObject in your default with sobjectType as it is the only way the sobject will be recognised in the controller.

Also, you return the id of the contact in your apex classes and set it as a the v.ConInfo which changes the type of the aura attribute and prevent any use after the first one.

| improve this answer | |

Try this ;)

You have to pass function parameter value in String format then deserialize them;

In the component controller pass string instead of a JavaScript object:

    "c": JSON.stringify(con)

Then in Apex deserialize the string

public static Id saveContact(String c) {
    Contact con = (Contact) Json.deserialize(c, Contact.class);
    if(con != null){
        insert con;
        return con.Id;           
    return null;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.