+ Start a Discussion
Andy Kallio 7Andy Kallio 7 

force:recordData reload not working for Admin

Hello Friends!

I have a server side class that needs the recordtype.developer name of the current record. I am trying to use lightning data service to get the developername. So, I have 2 <force:recordData> attributes. The first stores the current record and the second is for the recordType. So, my intention is get the recordTypeId from the current record and use the reloadRecord method to get LDS to populate the other fields I need. I can see that I am setting recordTypeId just fine but for some reason simpleRecordType remains null after the reloadRecord Command. Can anybody see what I am doing wrong?


    handleRecordUpdated: function(cmp, event, helper) {
        var eventParams = event.getParams();
        if(eventParams.changeType === "LOADED" || eventParams.changeType === "CHANGED") {
      		// get the simpleRecord attribute from the component
      		var simpleRecordTypeId = cmp.get('v.simpleRecord.RecordTypeId');
            var recordTypeId = cmp.get('v.recordTypeId');
            // if this is the first time we're loading the record then 
            // populate the ownerid and load the record
            if(recordTypeId == null){
                // assign the base record's ownerid onto the attribute we've
                // attached to the second force:recordData's recordid value.
                cmp.set('v.recordTypeId', simpleRecordTypeId);
                // fire the component event to reload the record now
                // that we've given it a record id.

            var actionVF = cmp.get('c.getVFOptions');
                sObjectName : cmp.get('v.sObjectName'),
                recordTypeName : cmp.get('v.simpleRecordType.DeveloperName')
            actionVF.setCallback(this, function(response) {
                var stateVF = response.getState();
                if(stateVF == "SUCCESS") {
                    var vfOptions;
                    vfOptions = response.getReturnValue();
                    var custs = [];
                    var conts = vfOptions.cOpts;
                    for(key in conts) {
                        custs.push({value:conts[key], key:key});
                    cmp.set('v.templateOptions', custs);   
                    var vfPage;
                    vfPage = vfOptions.vfPage;
                    cmp.set('v.vfPage', vfPage);
            // Send action off to be executed

        } else if(eventParams.changeType === "CHANGED") {
        } else if(eventParams.changeType === "REMOVED") {
            // record is deleted
        } else if(eventParams.changeType === "ERROR") {
            var errors = response.getError();
            console.log('errors '+errors);
    onSingleSelectChange: function(cmp) {
        var selectCmp = cmp.find("InputSelectSingle");
        cmp.set("v.selectedTemplate", selectCmp.get("v.value"));
    savePDF : function(cmp, event, helper) {
        var recordId = cmp.get("v.recordId");
        var selectedTemplate = cmp.get("v.selectedTemplate");
        var qName = cmp.get("v.simpleRecord.Name");
        var pdfName = selectedTemplate;
        var vfPage = cmp.get("v.vfPage"); 
        var action = cmp.get("c.savePDF_Quote");
            "vfPage": vfPage, 
            "recordId" : recordId, 
            "selectedTemplate" : selectedTemplate, 
            "pdfName" : qName
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                alert('Attachment saved successfully');
            else if (state === "INCOMPLETE") {
                // do something
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " + 
                    } else {
                        console.log("Unknown error");
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:hasSObjectName,lightning:isUrlAddressable" 
    <aura:attribute name="selectedTemplate" type="String"/>
    <aura:attribute name="templateOptions" type="List"/>
    <aura:attribute name="simpleRecord" type="Object"/> 
    <aura:attribute name="vfPage" type="String"/>
    <force:recordData aura:id="recordLoader"
        fields="Name, RecordTypeId"
    <aura:attribute name="recordTypeId" type="Id"/> <!-- assigned in Javascript after record load -->
    <aura:attribute name="simpleRecordType" type="RecordType"/>
    <aura:attribute name="recordTypeError" type="String"/>
    <force:recordData aura:id="recordType"
        fields="Id, Name, DeveloperName"
    <lightning:layout multipleRows="false">
        <lightning:layoutItem size="6">
        	<div class="row">
        		<!--<p class="title">Select Template:</p>-->
    			<ui:inputSelect class="single" aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}">
        			<option value="">...Select a Template...</option>
            		<aura:iteration items="{!v.templateOptions}" var="t_opt" indexVar="key">
                		<ui:inputSelectOption text="{!t_opt.value}" label="{!t_opt.key}"/>
    	<lightning:layoutItem size="6">
        <div class="slds-p-left_large">
    	 	<lightning:button label="Save PDF" title="Save PDF" onclick="{! c.savePDF }"/>
	<div class="slds-p-top_large">
        <p>PDF Preview:</p>
    	<c:pdfDI_DisplayTemplate selectedTemplate="{!v.selectedTemplate}" recordId2="{!v.recordId}" vfPage="{!v.vfPage}"/>

I have been using this as an example: https://github.com/aheber/ObjectAgnosticLightingComponent