0

I am trying to get an attribute set to the value returned on using response.getReturnValue(); and a thereafter a Boolean checked to true in a controller function.

This save function saves the record and returns the Record Id and sets it in a different attribute called recordId.

There's a change handler on recordId attribute which starts executing function doHandle***Change right after the value is set in save function.

ltngCmpController.js (Redacted code)

save: function(component, event, helper) {

console.log(":: saveMethod Executing");

//getting the information
console.log(":: Getting attribute from component");
var att= component.get("v.att");
console.log(":: Received Attribute : "+JSON.stringify(att));

//Validation for required field
console.log(":: Running Validation for attribute");
if($A.util.isEmpty(att.Name1__c) || $A.util.isUndefined(att.Name1__c)){
    alert('Client Name is Required!');
    console.log(":: Name is Required!");
    return;
}
console.log(":: Validation Successful!");

//Calling the Apex Function
console.log(":: Calling out Apex Function : createRecord1");
var action = component.get("c.createRecord1");

//Setting the Apex Parameter
console.log(":: Setting params in Apex Function");
action.setParams({
    att: att
});

//Setting the Callback
console.log(":: Setting callback");
action.setCallback(this,function(response){

    //get the response state
    var state = response.getState();

    //check if result is successful
    if(state == "SUCCESS"){
        console.log(":: Record Created Successfully");

        console.log(":: Setting return value to recordId Attribute");
        component.set("v.recordId",response.getReturnValue());
        console.log("setting return to recordId");
        component.set("v.BooleanCheck","True");
        console.log("setting boolean check to true")

        var pId=component.get("v.recordId");

        console.log(":: Attribute:recordId / var:pId= "+pId);
    }
    else if(state == "ERROR"){
        alert('Error in calling server side action');
    }
});

//adds the server-side action to the queue
console.log(":: Enqueuing server-side action");
$A.enqueueAction(action);
}

I tried to use console.log to verify when does the save function execution stops and it appears that it stops on this line component.set("v.recordId",response.getReturnValue()); and moves to doHandle***Change.

Console Screenshot

Screenshot of Browser Console

I am using pId just to verify if the value has been passed up to recordId attribute or not, there's no other significance to that variable.

I have moved forward by doing each of these operation before I set the value returned is set to the attribute but I want to know if this how it is supposed to be functioning?

  • 1
    How is the recordId attribute defined? – sfdcfox Jun 17 '19 at 11:49
  • it is not response.getResultValue() but component.set ("v.recordId",...); which does not work. – kurunve Jun 17 '19 at 11:49
  • sfdcfox - recordId attribute is defined as type="Quote". kurunve - Record is getting saved without any trouble, I also put the console.log(component.get("v.recordId") in the doHandle***Change method and it is returning correct record Id when accessed through another function executing after save function so I strongly believe component.set("v.recordId", response.getReturnValue()); is working. – shashankj Jun 17 '19 at 12:02
  • I still suspect you're tripping up an access check somewhere. component.getReturnValue does not terminate a script (otherwise, every single example of it would not work in the docs). If your return value is meant to be an Id, it should be defined as such <aura:attribute name="recordId" type="Id" access="public" />; if you're using force:hasRecordId, you should not be defining your own attribute of the same name, as that can cause unexpected behavior. – sfdcfox Jun 17 '19 at 12:33
  • agree with @sfdcfox, better to give a different name for recordid attribute if your component implemented a force:hasRecordId – sdandamud1 Jun 17 '19 at 15:46

Your Answer

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

Browse other questions tagged or ask your own question.