0

I am actually using force:recordData to get info from a task and then I want to create an event from it. So I created a lightning component to be used in a lightning action. The component code is as follow :

 <aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">
<!-- ************************************************************* -->
<!-- **************** AUTHOR  : SC (VMU)         *****************-->
<!-- **************** VERSION : 1.0              *****************-->
<!-- **************** SINCE   : 09/05/2018       *****************-->
<!-- ************************************************************* -->  
<aura:attribute name="record" type="Object"/>
<aura:attribute name="simpleRecord" type="Object"/>
<aura:attribute name="recordError" type="String"/>
<aura:attribute name="showSpinner" access="private" type="boolean" default="true" description="If true, show spinner" />
<!-- ************************************************************* -->
<!-- ****************      HANDLERS DEFINITION   *****************-->
<!-- ************************************************************* -->
<force:recordData aura:id="recordLoader"
                  recordId="{!v.recordId}"
                  fields="WhoId,ContactWhoId__c,Habitat__c"
                  targetRecord="{!v.record}"
                  targetError="{!v.recordError}"
                  targetFields="{!v.simpleRecord}"
                  layoutType="FULL"
                  recordUpdated="{!c.doInit}"/>
<!-- ************************************************************* -->
<!-- ****************         BODY               *****************-->
<!-- ************************************************************* -->
<aura:if isTrue="{!v.showSpinner}"> 
    <div class="slds-card__header" style="position:relative;height:200px">
      <div class="slds-form_compound">              
        <lightning:spinner variant="brand" size="medium"/>
      </div>
    </div>      
</aura:if>

My controller is like follow :

 ({
    doInit : function(component, event, helper) {
    console.log('## starting method  doInit');
    var param = {};
    var task = component.get("v.simpleRecord");
    console.log('## task :',task);
    param.WhoId = task.WhoId;
    param.ContactWhoId__c = task.ContactWhoId__c;
    param.Habitat__c = task.Habitat__c;

    console.log('## param :',param);
    component.set("v.showSpinner",false);
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Event",
        "defaultFieldValues": param
    });
    createRecordEvent.fire();
    $A.get("e.force:closeQuickAction").fire();   
 }
 })

Unfornately I'm obtaining the "Action failed: c:LC_CreateEventfromTask$controller$doInit [Cannot read property 'WhoId' of null]" error, and the task is null. What I am missing here?

2

Tasks are not currently supported in the Lightning Data Service. There's a list of supported objects in docs.

| improve this answer | |
0

targetRecord is populated with the current record, containing the fields relevant to the requested layoutType( consists of fields, childRelationships, apiName, id, recordTypeInfo.) or the fields listed in the fields attribute. targetFields is populated with a simplified view of the loaded record.

It is not necessary to use both the attribute.

({
doInit : function(component, event, helper) {
console.log('## starting method  doInit');
var param = {};
**var task = component.get("v.record");**
console.log('## task :',task);
param.WhoId = task.WhoId;

console.log('## param :',param);
component.set("v.showSpinner",false);
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
    "entityApiName": "Event",
    "defaultFieldValues": param
});
createRecordEvent.fire();
$A.get("e.force:closeQuickAction").fire();   
}
})
| improve this answer | |

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.