var objectType = component.get("v.sObjectName");
var createRecordEvent = $A.get("e.force:createRecord");
if(createRecordEvent){
if(recordTypeId){
switch (objectType) {
case "Account":
createRecordEvent.setParams({
"entityApiName": entityApiName,
"recordTypeId": recordTypeId,
"defaultFieldValues": {
"Account__c" : component.get("v.recordId")
}
});
createRecordEvent.fire();
break;
case "Opportunity":
createRecordEvent.setParams({
"entityApiName": entityApiName,
"recordTypeId": recordTypeId,
"defaultFieldValues": {
"Account__c" : component.get("v.Install_At__c"),
"Customer_Number__c" : component.get("v.Customer_Number__c"),
"New_Opp_Stage__c" : component.get("v.stageName"),
"Close_Date__c" : component.get("v.CloseDate"),
"BLUE_CRDD__c" : component.get("v.Install_Date__c"),
"Opp_Num__c" : component.get("v.Opp_Num__c"),
"Opportunity_Name__c" : component.get("v.recordId")
}
});
createRecordEvent.fire();
break;
}
So i was under the impression that when you perform force:hasRecordId it also snags the field data of that record, or was i wrong? Because right now when i do the fire the create record event it knows if it's an opportunity or account, so that works, but on opportunities it only passes the recordId nothing else.
Below is my cmp for reference, above is a portion of my JS helper, it's currently chained to the lightning:button variant="brand" label="Next" onclick="{!c.createRecord}"
<aura:component controller="Sales_recordType" implements="force:hasSObjectName,force:lightningQuickActionWithoutHeader,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="lstOfRecordType" type="String[]" />
<aura:attribute name="mapOfRecordType" type="Map" />
<aura:attribute name="lstOfDesc" type="String[]"/>
<aura:handler name="init" value="{!this}" action="{!c.fetchListOfRecordTypes}"/>
<lightning:layout multipleRows="true" horizontalAlign="center">
<lightning:layoutItem flexibility="auto" padding="around-small"
size="12"
largeDeviceSize="12"
mediumDeviceSize="12"
smallDeviceSize="12">
<lightning:formattedText value="Select Blue Record Type" />
</lightning:layoutItem>
<lightning:layoutItem flexibility="auto" padding="around-small"
size="12"
largeDeviceSize="12"
mediumDeviceSize="12"
smallDeviceSize="12">
<!-- select to hold all available record type names list -->
<lightning:select aura:id="recordTypePickList" name="selectRecordType" label="Select a Record Type">
<option value="" text="Select Record Type"/>
<aura:iteration items="{!v.lstOfRecordType}" var="item">
<option value="{!item}" text="{!item}"/>
</aura:iteration>
</lightning:select>
</lightning:layoutItem>
<lightning:layoutItem flexibility="auto" padding="around-small"
size="3"
largeDeviceSize="3"
mediumDeviceSize="3"
smallDeviceSize="6">
<lightning:button variant="brand" label="Next" onclick="{!c.createRecord}"/>
</lightning:layoutItem>
<lightning:layoutItem flexibility="auto" padding="around-small"
size="3"
largeDeviceSize="3"
mediumDeviceSize="3"
smallDeviceSize="6">
<lightning:button variant="neutral" label="Cancel" onclick="{!c.closeModal}" />
</lightning:layoutItem>
</lightning:layout>
<div class="slds-scrollable">
<table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer ">
<thead>
<tr class="slds-text-heading_label">
<th scope="col"><div class="slds-truncate" title="ID">Name</div></th>
<th scope="col"><div class="slds-truncate" title="Name">Description</div></th>
</tr>
</thead>
<tbody>
<!-- Table of descriptions -->
<aura:iteration items="{!v.lstOfDesc}" var="row">
<tr>
<th scope="row"><div class="slds-truncate" title="{!row.Name}">{!row.Name}</div></th>
<td><div class="slds-truncate" title="{!row.Name}">{!row.Description}</div></td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:component>
edit Ahh now i see there is such a thing as force:RecordData..... but how i see it set up in the examples is as a replacement for the aura:handler...now since the Force:createRecord function i have executes on a button press with field data retrieved during the initial execution of the component still be accessible? How would i structure that in, i've tried one way and it just fails on me.
solved used the and else to figure out the sOBject on the cmp level and do a force:recordData based on the sObject type.