0

I am trying to insert record and return recordId from apex class to aura component. But i could not log the data inside setcallback method.

Aura Code :

    try {
      var action3 = component.get('c.getCreatedFileId');
      action3.setCallback(this, function (response) {
        var responseValue = response.getReturnValue();
        console.log(responseValue);
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
          "recordId": responseValue.Id,
          "slideDevName": "detail"
        });
        navEvt.fire();
      });
      $A.enqueueAction(action3);
    
    }
}

Apex Code:

 @AuraEnabled
    public static ContentDocument getCreatedFileId(){
        system.debug('Deb1');
        ContentDocument Cd = [SELECT Id FROM ContentDocument WHERE CreatedDate = TODAY AND CreatedById =:UserInfo.getUserId() ORDER BY CreatedDate DESC LIMIT 1];
        system.debug('Deb2');
        return Cd;
    }


At last, i want to navigate to the returned recordID. Please help me out, thanks.

1 Answer 1

0

I think the way you are accessing the Id of the returned record needs adjustments, check below

  action3.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            var responseValue = response.getReturnValue();
            console.log('Returned Record ID: ' + responseValue.Id);
    
            var navEvt = $A.get("e.force:navigateToSObject");
            navEvt.setParams({
                "recordId": responseValue.Id,
                "slideDevName": "detail"
            });
            navEvt.fire();
        } else {
            console.error('Error: ' + response.getError());
        }
    });

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .