0

I am trying to populate the custom component with the record. and here is the component.

<aura:component implements="flexipage:availableForAllPageTypes" access="global" 
                controller="EngagementController" >
   <aura:attribute name="Engagements" type="String[]" />  
   <aura:attribute name="recordId" type="String" />

   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

   <force:recordData aura:id="recordLoader" 
                      recordId="{!v.recordId}"
                      fields="Id, ONPATTRO_Indication_MVN__c,
                              ONPATTRO_Indication_Notes__c,
                              ONPATTRO_Efficacy_Safety_MVN__c,
                              ONPATTRO_Efficacy_Safety_Notes__c,
                              ONPATTRO_Mechanism_Action_MVN__c,
                              ONPATTRO_Mechanism_Action_Notes__c,
                              ONPATTRO_Dosing_Administration_MVN__c,
                              ONPATTRO_Dosing_Administration_Notes__c,
                              ONPATTRO_Infusion_MVN__c,
                              ONPATTRO_Infusion_Notes__c,
                              Alnylam_Assist_Review_MVN__c,
                              Alnylam_Assist_Review_Notes__c,
                              hATTR_Review_MVN__c,
                              hATTR_Review_Notes__c,
                              hATTR_Hereditary_Nature_MVN__c,
                              hATTR_Hereditary_Nature_Notes__c,
                              hATTR_Symptoms_MVN__c,
                              hATTR_Symptoms_Notes__c,
                              hATTR_Amyloidosis__c,
                              hATTR_Amyloidosis_Notes__c,
                              hATTR_Amyloidosis_risk__c,
                              hATTR_Amyloidosis_risk_Notes__c,
                              hATTR_Resources_MVN__c,
                              hATTR_Resources_Notes__c,
                              Alnylam_Act_Review_MVN__c,
                              Alnylam_Act_Review_Notes__c"
                      targetFields="{!v.Engagements}"/>

    <div class="slds-tile__detail  slds-scrollable--y"   >
        <dl class="slds-list_horizontal slds-wrap">
            <dt class="slds-item_label slds-text-color_weak" Style="text-align:center; margin: 2px 2px; width:50%;" >
                <input type="checkbox" name="default" /> 
                Indication of ONPATTRO {!v.Engagements.Id}

            </dt>

        </dl>
    </div>
</aura:component>

where

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

is populated form another component.

<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> function is running fine but when it comes to setting up values to Engagements component.set("v.Engagements", result); function is not working in following controller.

({
    doInit : function(component, event, helper) {
        var action = component.get("c.getDiscussion");
        var recordId = component.get("v.recordId");
        alert(recordId);
      action.setParams({ "recordId":recordId });
        console.log(component.get("v.recordId"));
        action.setCallback(this, function(e) {
           if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue(); 
               console.log(result);
                component.set("v.Engagements", result);
            }
        });
        $A.enqueueAction(action);
    },

})

the Apex controller is given here.

@AuraEnabled
    public static PEL_Engagement_MVN__c getDiscussion(String recordId) {
        system.debug('****'+recordId);
        PEL_Engagement_MVN__c Engagement = [Select  Id,ONPATTRO_Indication_MVN__c,
                                                    ONPATTRO_Indication_Notes__c,
                                                    ONPATTRO_Efficacy_Safety_MVN__c,
                                                    ONPATTRO_Efficacy_Safety_Notes__c,
                                                    ONPATTRO_Mechanism_Action_MVN__c,
                                                    ONPATTRO_Mechanism_Action_Notes__c,
                                                    ONPATTRO_Dosing_Administration_MVN__c,
                                                    ONPATTRO_Dosing_Administration_Notes__c,
                                                    ONPATTRO_Infusion_MVN__c,
                                                    ONPATTRO_Infusion_Notes__c,
                                                    Alnylam_Assist_Review_MVN__c,
                                                    Alnylam_Assist_Review_Notes__c,
                                                    hATTR_Review_MVN__c,
                                                    hATTR_Review_Notes__c,
                                                    hATTR_Hereditary_Nature_MVN__c,
                                                    hATTR_Hereditary_Nature_Notes__c,
                                                    hATTR_Symptoms_MVN__c,
                                                    hATTR_Symptoms_Notes__c,
                                                    hATTR_Amyloidosis__c,
                                                    hATTR_Amyloidosis_Notes__c,
                                                    hATTR_Amyloidosis_risk__c,
                                                    hATTR_Amyloidosis_risk_Notes__c,
                                                    hATTR_Resources_MVN__c,
                                                    hATTR_Resources_Notes__c,
                                                    Alnylam_Act_Review_MVN__c,
                                                    Alnylam_Act_Review_Notes__c
                                                    from    PEL_Engagement_MVN__c 
                                                    where Id =: recordId];
    System.debug('Hi ::::' +Engagement);
        return Engagement;
    }

Thanks Advance.

  • can you show getDiscussion apex method and also what you are getting in log – salesforce-sas Aug 23 '19 at 14:49
  • okay let me edit my my question you will see it – shafi jan Aug 23 '19 at 14:53
1

Engagements will be automatically be populated with values for mentioned fields for the record as its using lightning data service force:recordData. Also it should be of type Object instead of String[] - else it will not load.

You dont need doInit method and apex method as you are just fetching same record.

Use aura:if since you are passing it from another component. When does recordId gets passed to this component depends on how the parent component is processing it.

<aura:attribute name="Engagements" type="Object" />  
<aura:attribute name="recordId" type="String" />

<aura:if isTrue="{!not(empty(v.recordId))}">
    <force:recordData aura:id="recordLoader" 
                      recordId="{!v.recordId}"
                      fields="Id, ONPATTRO_Indication_MVN__c,
                              ONPATTRO_Indication_Notes__c,
                              ONPATTRO_Efficacy_Safety_MVN__c,
                              ONPATTRO_Efficacy_Safety_Notes__c,
                              ONPATTRO_Mechanism_Action_MVN__c,
                              ONPATTRO_Mechanism_Action_Notes__c,
                              ONPATTRO_Dosing_Administration_MVN__c,
                              ONPATTRO_Dosing_Administration_Notes__c,
                              ONPATTRO_Infusion_MVN__c,
                              ONPATTRO_Infusion_Notes__c,
                              Alnylam_Assist_Review_MVN__c,
                              Alnylam_Assist_Review_Notes__c,
                              hATTR_Review_MVN__c,
                              hATTR_Review_Notes__c,
                              hATTR_Hereditary_Nature_MVN__c,
                              hATTR_Hereditary_Nature_Notes__c,
                              hATTR_Symptoms_MVN__c,
                              hATTR_Symptoms_Notes__c,
                              hATTR_Amyloidosis__c,
                              hATTR_Amyloidosis_Notes__c,
                              hATTR_Amyloidosis_risk__c,
                              hATTR_Amyloidosis_risk_Notes__c,
                              hATTR_Resources_MVN__c,
                              hATTR_Resources_Notes__c,
                              Alnylam_Act_Review_MVN__c,
                              Alnylam_Act_Review_Notes__c"
                      targetFields="{!v.Engagements}"/>

    <div class="slds-tile__detail  slds-scrollable--y"   >
        <dl class="slds-list_horizontal slds-wrap">
            <dt class="slds-item_label slds-text-color_weak" Style="text-align:center; margin: 2px 2px; width:50%;" >
                <input type="checkbox" name="default" /> 
                Indication of ONPATTRO {!v.Engagements.Id}
            </dt>

        </dl>
    </div>
</aura:if>
| improve this answer | |
  • by setting the String[] to Object type I am still getting the results – shafi jan Aug 23 '19 at 15:00
  • I have edit my question and share the Apex class. – shafi jan Aug 23 '19 at 15:16
  • It should be only Object type. Check the answer – salesforce-sas Aug 23 '19 at 15:28

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.