0

I am working on a project where previously some SF developer has done some Aura components. I don't have previous experience in frontend or javascript at all, or at least I don't have deep understanding of how it works within Salesforce and his data retrieving system.

So, with this code:

<aura:component controller="CMP_Apex_Path_OportunidadPrincipal" description="CMP_Path_OportunidadPrincipal"
implements="force:hasRecordId,flexipage:availableForAllPageTypes">

<aura:attribute name="recordId" type="Opportunity" />

<aura:attribute name="fechaFinalizacion" type="Date" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<force:recordData recordId="{!v.recordId}"
    fields="Subestados__c,Subestados_Calificacion__c,Subestados_Contratacion__c,Subestados_Envio_finalistas__c,Subestados_Seleccion__c,Estados_Oportunidad__c,fecha_de_incorporacion__c"
    recordUpdated="{!c.doInit}" />

Can someone explain to me, how <aura:attribute name="fechaFinalizacion" type="Date" /> works? How does SF aura component populate the value of Fecha_finalizacion__c from Opportunity without retrieving it from the controller (In the controller class there's no query where this field is retrieved).

Does that mean if I need to retrieve x__c field from Opportunity can I just code

 "aura:attribute name=newfield__c " type ="Date" 

And it will populate itself?

Thank you in advance...

ApexController:

public with sharing class CMP_Apex_Path_OportunidadPrincipal {
@AuraEnabled
public static List<String> setListStatusPrincipal(String recordId) {
    List<String> listStatus = new List<String>();

    try {
        Opportunity oportunidad = [select Id, Name,StageName,Estados_Oportunidad__c from Opportunity where Id =: recordId];

        Schema.DescribeFieldResult fieldResult = Opportunity.Estados_Oportunidad__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            listStatus.add(pickListVal.getLabel());
        }
        if(oportunidad.Estados_Oportunidad__c=='Cerrada ganada'){
            listStatus.remove(listStatus.size()-1);
        }else if(oportunidad.Estados_Oportunidad__c=='Cerrada perdida'){
            listStatus.remove(listStatus.size()-2);
        }else{
            listStatus.remove(listStatus.size()-1);
            listStatus.remove(listStatus.size()-1);
            listStatus.add('Cerrada');
        }


    } catch (Exception e) {
        throw new AuraHandledException('Error: ' + e.getMessage() + ' - ' + e.getLineNumber());
    }

    return listStatus;
}

@AuraEnabled
public static List<String> setListStatus(String recordId) {
    List<String> listStatus = new List<String>();

    try {
        Opportunity oportunidad = [select Id, Name,StageName, Estados_Oportunidad__c from Opportunity where Id =: recordId];

        switch on oportunidad.Estados_Oportunidad__c {
            when 'Calificación' {
                Schema.DescribeFieldResult fieldResult = Opportunity.Subestados_Calificacion__c.getDescribe();
                List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
                for( Schema.PicklistEntry pickListVal : ple){
                    listStatus.add(pickListVal.getLabel());
                }
            }
            when 'Selección' {
                Schema.DescribeFieldResult fieldResult = Opportunity.Subestados_Seleccion__c.getDescribe();
                List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
                for( Schema.PicklistEntry pickListVal : ple){
                    listStatus.add(pickListVal.getLabel());
                }
            }
            when 'Finalistas' {
                Schema.DescribeFieldResult fieldResult = Opportunity.Subestados_Envio_finalistas__c.getDescribe();
                List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
                for( Schema.PicklistEntry pickListVal : ple){
                    listStatus.add(pickListVal.getLabel());
                }
            }
            when 'Contratación' {
                Schema.DescribeFieldResult fieldResult = Opportunity.Subestados_Contratacion__c.getDescribe();
                List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
                for( Schema.PicklistEntry pickListVal : ple){
                    listStatus.add(pickListVal.getLabel());
                }
            }
        }

    } catch (Exception e) {
        throw new AuraHandledException('Error: ' + e.getMessage() + ' - ' + e.getLineNumber());
    }

    return listStatus;
}

@AuraEnabled
public static String setStatusPrincipal(String recordId) {
    String status = '';

    try {
        Opportunity oportunidad = [select Id, Name,toLabel(StageName), toLabel(Estados_Oportunidad__c) from Opportunity where Id =: recordId];

        status=oportunidad.Estados_Oportunidad__c;

    } catch (Exception e) {
        throw new AuraHandledException('Error: ' + e.getMessage() + ' - ' + e.getLineNumber());
    }
    return status;
}

@AuraEnabled
public static String setStatus(String recordId) {
    String status = '';

    try {
        Opportunity oportunidad = [select Id, Name,toLabel(Estados_Oportunidad__c), toLabel(Subestados_Calificacion__c),toLabel(Subestados_Seleccion__c),
                toLabel(Subestados_Envio_finalistas__c),toLabel(Subestados_Contratacion__c) from Opportunity where Id =: recordId];
        switch on oportunidad.Estados_Oportunidad__c {
            when 'Calificación' {
                status=oportunidad.Subestados_Calificacion__c;
            }
            when 'Selección' {
                status=oportunidad.Subestados_Seleccion__c;
            }
            when 'Finalistas' {
                status=oportunidad.Subestados_Envio_finalistas__c;
            }
            when 'Contratación' {
                status=oportunidad.Subestados_Contratacion__c;
            }
        }
    } catch (Exception e) {
        throw new AuraHandledException('Error: ' + e.getMessage() + ' - ' + e.getLineNumber());
    }
    return status;
}

@AuraEnabled
public static String completarEtapaPrincipal(String recordId,List<String> Lista,String valor) {
    Opportunity oportunidad = [select Id, Name,toLabel(StageName), toLabel(Estados_Oportunidad__c) from Opportunity where Id =: recordId];
    String status = valor;
    Integer posicion = Lista.indexOf(valor);
    System.debug(valor);
    if(posicion+1<Lista.size()){
        status=Lista.get((posicion+1));
        System.debug(status);
    }
    oportunidad.Estados_Oportunidad__c=status;

    update oportunidad;
    return status;
}

@AuraEnabled
public static String completarEtapa(String recordId,List<String> Lista,String valor) {
    Opportunity oportunidad = [select Id, Name,toLabel(Estados_Oportunidad__c), toLabel(Subestados_Calificacion__c),toLabel(Subestados_Seleccion__c),
            toLabel(Subestados_Envio_finalistas__c),toLabel(Subestados_Contratacion__c) from Opportunity where Id =: recordId];
    String status = valor;
    Integer posicion = Lista.indexOf(valor);
    System.debug(valor);
    if(posicion+1<Lista.size()){
        status=Lista.get((posicion+1));
        System.debug(status);
    }

    switch on oportunidad.Estados_Oportunidad__c {
        when 'Calificación' {
            oportunidad.Subestados_Calificacion__c=status;
        }
        when 'Selección' {
            oportunidad.Subestados_Seleccion__c=status;
        }
        when 'Finalistas' {
            oportunidad.Subestados_Envio_finalistas__c=status;
        }
        when 'Contratación' {
            oportunidad.Subestados_Contratacion__c=status;
        }
    }

    update oportunidad;
    return status;
}

@AuraEnabled
public static String ActualizarEstadoApexPrincipal(String recordId,String valor) {
    Opportunity oportunidad = [select Id, Name,toLabel(StageName), toLabel(Estados_Oportunidad__c) from Opportunity where Id =: recordId];

    oportunidad.Estados_Oportunidad__c=valor;

    update oportunidad;
    return valor;
}

@AuraEnabled
public static String ActualizarEstadoApex(String recordId,String valor) {
    Opportunity oportunidad = [select Id, Name,toLabel(Estados_Oportunidad__c), toLabel(Subestados_Calificacion__c),toLabel(Subestados_Seleccion__c),
            toLabel(Subestados_Envio_finalistas__c),toLabel(Subestados_Contratacion__c) from Opportunity where Id =: recordId];

    switch on oportunidad.Estados_Oportunidad__c {
        when 'Calificación' {
            oportunidad.Subestados_Calificacion__c=valor;
        }
        when 'Selección' {
            oportunidad.Subestados_Seleccion__c=valor;
        }
        when 'Finalistas' {
            oportunidad.Subestados_Envio_finalistas__c=valor;
        }
        when 'Contratación' {
            oportunidad.Subestados_Contratacion__c=valor;
        }
    }

    update oportunidad;
    return valor;
}
@AuraEnabled
public static boolean ComprobarPagado(String recordId){
    boolean Valor;
    Opportunity oportunidad = [SELECT Id,StageName,Avanzar_sin_pago__c,Pagado__c FROM Opportunity where Id =: recordId];

    if(oportunidad.Pagado__c==true||oportunidad.Avanzar_sin_pago__c==true){
        Valor=true;
    }else{
        Valor=false;
    }


    return Valor;
}
@AuraEnabled
public static List<String> ActualizarCerradaGanada(String recordId,List<String> Lista){

    Opportunity oportunidad = [SELECT Id,StageName,Avanzar_sin_pago__c,Pagado__c,Estados_Oportunidad__c FROM Opportunity where Id =: recordId];
    oportunidad.Estados_Oportunidad__c='Cerrada ganada';
    Lista.remove(Lista.size()-1);
    Lista.add('Cerrada ganada');
    update oportunidad;
    return Lista;
}
@AuraEnabled
public static List<String> ActualizarCerradaPerdida(String recordId,List<String> Lista,String Motivo,String Otro,date fechaFin){
    system.debug('fechaFin' + fechaFin);
    Opportunity oportunidad = [SELECT Id,StageName,Motivo_perdida_oportunidad__c,Otros_Motivos_de_perdida__c,Fecha_de_finalizacion__c,Avanzar_sin_pago__c,Pagado__c,Estados_Oportunidad__c FROM Opportunity where Id =: recordId];
    oportunidad.Estados_Oportunidad__c='Cerrada perdida';
    oportunidad.Motivo_perdida_oportunidad__c=Motivo;
    oportunidad.Otros_Motivos_de_perdida__c=Otro;
    oportunidad.Fecha_de_finalizacion__c = fechaFin;
    Lista.remove(Lista.size()-1);
    Lista.add('Cerrada perdida');
    update oportunidad;
    return Lista;
}
@AuraEnabled
public static List<String> ReiniciarLista(String recordId) {
    List<String> listStatus = new List<String>();

    try {
        Opportunity oportunidad = [select Id, Name,StageName, Subestados_Seleccion_Final__c from Opportunity where Id =: recordId];

        Schema.DescribeFieldResult fieldResult = Opportunity.Estados_Oportunidad__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            listStatus.add(pickListVal.getLabel());
        }

        listStatus.remove(listStatus.size()-1);
        listStatus.remove(listStatus.size()-1);
        listStatus.add('Cerrada');



    } catch (Exception e) {
        throw new AuraHandledException('Error: ' + e.getMessage() + ' - ' + e.getLineNumber());
    }

    return listStatus;
}

}

jSController

({
doInit : function (component, event, helper) {
        helper.getListStatus(component, event, helper);
        helper.getStatus(component, event, helper);
        helper.getListStatusPrincipal(component, event, helper);
        helper.getStatusPrincipal(component, event, helper);
        helper.ComprobarPago(component);
    },
    CompletarPrincipal : function (component, event, helper) {
        helper.ComprobarPagoCompletar(component);
    },
    Completar : function (component, event, helper) {
        helper.CompletarEtapaHelper(component, event, helper);

    },
    SeleccionarEstadoPrincipal : function (component, event, helper) {
        var valor = event.getSource().get('v.value');
        component.set('v.EstadoSeleccionadoPrincipal',valor);
    },
    SeleccionarEstado : function (component, event, helper) {
        var valor = event.getSource().get('v.value');
        component.set('v.EstadoSeleccionado',valor);
    },
    ActualizarEstadoPrincipal : function (component, event, helper) {
        helper.ComprobarPagoActualizar(component);
    },
    ActualizarEstado : function (component, event, helper) {
        helper.ActualizarEstadoHelper(component, event, helper);
    },
    openModal : function(component, event, helper) {
        //if(component.get('v.Pagado')==true){
           component.set('v.modal', true);
            var cmpTarget = component.find('modalPadre');
            var cmpBack = component.find('modalbackdrop');
            $A.util.addClass(cmpTarget, 'slds-fade-in-open');
            $A.util.addClass(cmpBack, 'slds-backdrop--open');
            var target = component.find('modalHijo');
        /*}else{
            var toastEvent = $A.get("e.force:showToast");
                        toastEvent.setParams({
                            title : 'Error',
                            message: 'No se puede Cambiar de etapa por falta de pago',
                            duration:' 4000',
                            key: 'info_alt',
                            type: 'Error',
                            mode: 'pester'
                        });
                        toastEvent.fire();
        }*/

    },
    closeModal : function(component, event, helper){
        var cmpTarget = component.find('modalPadre');
        var cmpBack = component.find('modalbackdrop');

        $A.util.removeClass(cmpTarget, 'slds-fade-in-open');
        $A.util.removeClass(cmpBack, 'slds-backdrop--open');

        component.set('v.modal',false);
    },
    SeleccionarCerrada : function(component, event, helper){
        if(component.get('v.TipoCerrada')=='Cerrada ganada'){
            if(component.get('v.Pagado')==true){
                helper.ActualizarCerradaGanadaHelper(component, event, helper);
                 var action = component.get('c.closeModal');
            }else{
                var toastEvent = $A.get("e.force:showToast");
                    toastEvent.setParams({
                         title : 'Error',
                         message: 'No se puede Cambiar de etapa por falta de pago',
                         duration:' 4000',
                         key: 'info_alt',
                         type: 'Error',
                         mode: 'pester'
                    });
                    toastEvent.fire();
            }
         var action = component.get('c.closeModal');
        }else{
             if(component.get("v.fechaFinalizacion") == null){
                var toastEvent = $A.get("e.force:showToast");
                                toastEvent.setParams({
                                    title : 'Error',
                                    message: 'Debes de rellenar la fecha de finalización',
                                    duration:' 4000',
                                    key: 'info_alt',
                                    type: 'Error',
                                    mode: 'pester'
                                });
                                toastEvent.fire();
           
            
             }else{
                  var action = component.get('c.closeModal');
                  helper.ActualizarCerradaPerdidaHelper(component, event, helper);
             }
           
        }
        helper.getListStatus(component, event, helper);
        helper.getStatus(component, event, helper);
        $A.enqueueAction(action);
    }

});

JSHelper

({
getListStatusPrincipal: function (component, event, helper) {
    var action = component.get('c.setListStatusPrincipal');
    action.setParams({ "recordId": component.get("v.recordId"), });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            var rows = response.getReturnValue();
            component.set('v.listStatusPrincipal', rows);
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
getListStatus: function (component, event, helper) {
    var action = component.get('c.setListStatus');
    action.setParams({ "recordId": component.get("v.recordId"), });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            var rows = response.getReturnValue();
            component.set('v.listStatus', rows);
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
getStatusPrincipal: function (component, event, helper) {
    var action = component.get('c.setStatusPrincipal');
    action.setParams({ "recordId": component.get("v.recordId"), });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            component.set('v.currentStatusPrincipal', response.getReturnValue());
            component.set('v.EstadoSeleccionadoPrincipal', response.getReturnValue());
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
getStatus: function (component, event, helper) {
    var action = component.get('c.setStatus');
    action.setParams({ "recordId": component.get("v.recordId"), });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            component.set('v.currentStatus', response.getReturnValue());
            component.set('v. bßß', response.getReturnValue());
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
CompletarEtapaHelperPrincipal: function (component, event, helper) {
    var action = component.get('c.completarEtapaPrincipal');
    action.setParams({ "recordId": component.get("v.recordId"), "Lista": component.get("v.listStatusPrincipal"), "valor": component.get("v.currentStatusPrincipal") });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            var rows = response.getReturnValue();
            console.log('Status: ' + rows);
            component.set('v.currentStatusPrincipal', rows);
            component.set('v.EstadoSeleccionadoPrincipal', rows);
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                title: 'Éxito',
                message: 'Se ha Completado la Etapa',
                duration: ' 4000',
                key: 'info_alt',
                type: 'success',
                mode: 'pester'
            });
            toastEvent.fire();
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
CompletarEtapaHelper: function (component, event, helper) {
    var action = component.get('c.completarEtapa');
    action.setParams({ "recordId": component.get("v.recordId"), "Lista": component.get("v.listStatus"), "valor": component.get("v.currentStatus") });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            var rows = response.getReturnValue();
            console.log('Status: ' + rows);
            component.set('v.currentStatus', rows);
            component.set('v.EstadoSeleccionado', rows);
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                title: 'Éxito',
                message: 'Se ha Completado la Etapa',
                duration: ' 4000',
                key: 'info_alt',
                type: 'success',
                mode: 'pester'
            });
            toastEvent.fire();
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
ActualizarEstadoHelperPrincipal: function (component, event, helper) {
    var action = component.get('c.ActualizarEstadoApexPrincipal');
    action.setParams({ "recordId": component.get("v.recordId"), "valor": component.get("v.EstadoSeleccionadoPrincipal") });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            var rows = response.getReturnValue();
            console.log('Status: ' + rows);
            component.set('v.currentStatusPrincipal', rows);
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                title: 'Éxito',
                message: 'Se ha Actualizado la Etapa',
                duration: ' 4000',
                key: 'info_alt',
                type: 'success',
                mode: 'pester'
            });
            toastEvent.fire();
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
ActualizarEstadoHelper: function (component, event, helper) {
    var action = component.get('c.ActualizarEstadoApex');
    action.setParams({ "recordId": component.get("v.recordId"), "valor": component.get("v.EstadoSeleccionado") });

    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            var rows = response.getReturnValue();
            console.log('Status: ' + rows);
            component.set('v.currentStatus', rows);
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                title: 'Éxito',
                message: 'Se ha Actualizado la Etapa',
                duration: ' 4000',
                key: 'info_alt',
                type: 'success',
                mode: 'pester'
            });
            toastEvent.fire();
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
ComprobarPago: function (component) {
    var action = component.get("c.ComprobarPagado");
    action.setParams({ 'recordId': component.get("v.recordId") });
    action.setCallback(this, function (actionResult) {
        var state = actionResult.getState();
        if (component.isValid() && state === "SUCCESS") {
            console.log(JSON.stringify(actionResult.getReturnValue()));
            component.set("v.Pagado", actionResult.getReturnValue());
        }
    });
    $A.enqueueAction(action);
},
ComprobarPagoCompletar: function (component) {
    var action = component.get("c.ComprobarPagado");
    action.setParams({ 'recordId': component.get("v.recordId") });
    action.setCallback(this, function (actionResult) {
        var state = actionResult.getState();
        if (component.isValid() && state === "SUCCESS") {
            console.log(JSON.stringify(actionResult.getReturnValue()));
            component.set("v.Pagado", actionResult.getReturnValue());

            if (component.get('v.currentStatusPrincipal') == 'stand-by') {
                var action = component.get('c.openModal');
                $A.enqueueAction(action);
            } else {
                if (component.get('v.currentStatusPrincipal') == 'Calificación') {
                    if (component.get('v.Pagado') == true) {
                        this.CompletarEtapaHelperPrincipal(component);
                        this.getListStatus(component);
                        this.getStatus(component);
                    } else {
                        var toastEvent = $A.get("e.force:showToast");
                        toastEvent.setParams({
                            title: 'Error',
                            message: 'No se puede Cambiar de etapa por falta de pago',
                            duration: ' 4000',
                            key: 'info_alt',
                            type: 'Error',
                            mode: 'pester'
                        });
                        toastEvent.fire();
                    }
                } else {
                    this.CompletarEtapaHelperPrincipal(component);
                    this.getListStatus(component);
                    this.getStatus(component);
                }
            }
        }
    });
    $A.enqueueAction(action);
},
ComprobarPagoActualizar: function (component) {
    var action = component.get("c.ComprobarPagado");
    action.setParams({ 'recordId': component.get("v.recordId") });
    action.setCallback(this, function (actionResult) {
        var state = actionResult.getState();
        if (component.isValid() && state === "SUCCESS") {
            console.log(JSON.stringify(actionResult.getReturnValue()));
            component.set("v.Pagado", actionResult.getReturnValue());
            console.log(component.get('v.EstadoSeleccionadoPrincipal'));
            if (component.get('v.EstadoSeleccionadoPrincipal') == 'Cerrada') {
                var action = component.get('c.openModal');
                $A.enqueueAction(action);
            } else {
                if (component.get('v.currentStatusPrincipal') == 'Calificación' || component.get('v.currentStatusPrincipal') == 'stand-by' || component.get('v.currentStatusPrincipal') == 'Cerrada perdida') {
                    if (component.get('v.Pagado') == true || component.get('v.EstadoSeleccionadoPrincipal') == 'Cerrada' || component.get('v.EstadoSeleccionadoPrincipal') == 'stand-by' || component.get('v.EstadoSeleccionadoPrincipal') == 'Calificación') {
                        this.ActualizarEstadoHelperPrincipal(component);
                        this.getListStatus(component);
                        this.getStatus(component);
                        this.getListStatusPrincipal(component);
                    } else {
                        var toastEvent = $A.get("e.force:showToast");
                        toastEvent.setParams({
                            title: 'Error',
                            message: 'No se puede Cambiar de etapa por falta de pago',
                            duration: ' 4000',
                            key: 'info_alt',
                            type: 'Error',
                            mode: 'pester'
                        });
                        toastEvent.fire();
                    }
                } else {
                    if (component.get('v.currentStatusPrincipal') == 'Cerrada ganada' || component.get('v.currentStatusPrincipal') == 'Cerrada perdida') {
                        this.ReiniciarListaHelper(component);
                    }
                    this.ActualizarEstadoHelperPrincipal(component);
                    this.getListStatus(component);
                    this.getStatus(component);
                }
            }
        }
    });
    $A.enqueueAction(action);
},
ActualizarCerradaGanadaHelper: function (component, event, helper) {
    var action = component.get('c.ActualizarCerradaGanada');
    action.setParams({ "recordId": component.get("v.recordId"), "Lista": component.get("v.listStatusPrincipal"), });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            var rows = response.getReturnValue();
            component.set('v.listStatusPrincipal', rows);
            component.set('v.currentStatusPrincipal', 'Cerrada ganada');
            component.set('v.EstadoSeleccionadoPrincipal', 'Cerrada ganada');
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
ActualizarCerradaPerdidaHelper: function (component, event, helper) {
    var action = component.get('c.ActualizarCerradaPerdida');
    console.log(': ' + component.get("v.fechaFinalizacion"))
    action.setParams({ "recordId": component.get("v.recordId"), "Lista": component.get("v.listStatusPrincipal"), "Motivo": component.get("v.MotivoPerdida"), "Otro": component.get("v.OtroMotivo"), "fechaFin": component.get("v.fechaFinalizacion") });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            var rows = response.getReturnValue();
            component.set('v.listStatusPrincipal', rows);
            component.set('v.currentStatusPrincipal', 'Cerrada perdida');
            component.set('v.EstadoSeleccionadoPrincipal', 'Cerrada perdida');
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
ReiniciarListaHelper: function (component, event, helper) {
    var action = component.get('c.ReiniciarLista');
    action.setParams({ "recordId": component.get("v.recordId"), });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state == "SUCCESS") {
            var rows = response.getReturnValue();
            component.set('v.listStatusPrincipal', rows);
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
4
  • Hi, thanks for your question. Could you please include the controller and helper aspects of the Aura component as well? The HTML file that you've included don't provide enough information to answer your question. Dec 20, 2023 at 20:12
  • @CallumMacErlich Hi, thanks your for help in advance, I have added the controller and the helper Dec 20, 2023 at 21:02
  • From your code, it doesn't look like it's being fetched at all. It might be being passed into your component via the URL or via the attribute being set on the Lightning Page. To answer your specific question though, no you can't just include a reference to a field and expect it to be set automatically. You'd typically need to retrieve it in your controller and then set the attribute value. Dec 20, 2023 at 21:11
  • Thank you @CallumMacErlich Dec 21, 2023 at 8:58

1 Answer 1

0

Instead of using a single field, you need to create an Aura attribute of the type object.

<aura:attribute name="oppRecord" type="Object"/>

<force:recordData recordId="{!v.recordId}"
        fields="Subestados__c,Subestados_Calificacion__c,Subestados_Contratacion__c,Subestados_Envio_finalistas__c,Subestados_Seleccion__c,Estados_Oportunidad__c,fecha_de_incorporacion__c"
        targetFields="{!v.oppRecord}"
        recordUpdated="{!c.recordUpdate}"
        />

<!--controller.js-->
recordUpdate: function(component, event, helper) {
        alert(component.get("v.oppRecord").fecha_de_incorporacion__c);
    }

4
  • How does SF know that OppRecord of type Object its a Opportunity? Dec 21, 2023 at 8:58
  • The object is a generic type you can add any type of object to it. It doesn't matter. Dec 21, 2023 at 12:19
  • That's not accurate. While you can do this, you don't have to use an Object attribute to achieve it. This still doesn't answer the question from the OP as to how the data will actually be retrieved either. Dec 21, 2023 at 20:23
  • The data is being retried using force:recordData and once the data is fetched you can use it in recordUpdate. You can assign the fecha_de_incorporacion__c to other attribute. Dec 22, 2023 at 4:45

You must log in to answer this question.

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