I am trying to convert my Classic custom Javascript buttons to Lightning Experience actions buttons. Salesforce has a service to do this automatically, but the generated code is not very good. In my case it's outright wrong. But it is a starting point.
This is my component, I have added the force:recordData and the implements parts to the generated component:
<aura:component controller="OpportunityUtil" implements="force:hasRecordId" extends="c:LCC_GenericLightningComponent" >
<aura:handler event="c:LCC_GenericApplicationEvent" action="{!c.apexExecute}"/>
<aura:set attribute="partially" value="false"></aura:set>
<aura:attribute name="showAlert" type="Boolean" default="false"/>
<aura:attribute name="alertText" type="String"/>
<aura:attribute name="simpleContactRecord" type="Object"/>
<aura:attribute name="recordLoadError" type="String"/>
<force:recordData aura:id="recordLoader"
recordId="{!v.sObjectInfo.Id}"
layoutType="FULL"
targetError="{!v.recordLoadError}"
targetFields="{!v.simpleContactRecord}"
recordUpdated="{!c.handleRecordLoaded}"
/>
<div class="slds-scrollable slds-p-around_medium slds-text-heading_small" id="modal-content-id-1">
<aura:if isTrue="{!v.showAlert}">
<p class="slds-hyphenate" style="height: 6.75rem;">{!v.alertText}</p>
<aura:set attribute="else">
<div style="height: 6.75rem;">
<div role="status" class="slds-spinner slds-spinner_large slds-spinner_brand">
<span class="slds-assistive-text">Loading</span>
<div class="slds-spinner__dot-a"></div>
<div class="slds-spinner__dot-b"></div>
</div>
</div>
</aura:set>
</aura:if>
<br/>
</div>
<div class="slds-modal__footer">
<lightning:button class="slds-button_brand" onclick="{!c.accept}" label="Accept"/>
</div>
This is my controller, I have changed and simplified it compared to the generated code:
({
apexExecute : function(component, event, helper) {
},
accept : function(component, event, helper) {
},
handleRecordLoaded : function(component, event, helper) {
console.log('inside handleRecordLoaded');
}
})
The function handleRecordLoaded is never called. My Javascript experience is limited, so it's probably something simple, I think and hope.
I have found an explanation for the use of targetFields and targetRecord here