function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC_RichieSFDC_Richie 

Lightning Cmp.: e.force:createRecord with default values - error

Hello folks,

i am not very experienced with coding, but I just want to create a very simple record creation functionality with the event "e.force:createRecord".
I have the following plan:

I want to create a button on the task layout to create a new task record that is partly based on the present task.
Its basically a follow up task were I just want to take over some field values like whoid and whatid to
save some time for users. If users click the button a record creation window is opening with some default values that
can be changed if needed.

Here is my code:
<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId"
                access="global">
    
	<aura:attribute name="record" type="Object"/>
	<aura:attribute name="simpleRecord" type="Object"/>
	<aura:attribute name="recordError" type="String"/>
    
    <aura:attribute name="taskfields" type="Object"/>
    
    <force:recordData aura:id="recordLoader"
        recordId="{!v.recordId}"
        targetRecord="{!v.record}"
        layoutType="FULL"
        targetFields="{!v.simpleRecord}"
        targetError="{!v.recordError}"
        fields="Id, Name, WhoId, Description, WhatId"
        />
    
    <lightning:button label="Erstelle Folgeaufgabe" variant="brand" onclick="{!c.createFollowUpTask}"/>
    
</aura:component>
 
({
 createFollowUpTask: function (component) {
        var createRecordEvent = $A.get('e.force:createRecord');
     	var recordId = component.get("v.recordId");
     	var simpleRecord = component.get("v.simpleRecord");
        if ( createRecordEvent ) {
            createRecordEvent.setParams({
                'entityApiName': 'Task',
                'defaultFieldValues': {
                    'Subject' : 'tasksubject',
                	'WhoId' : simpleRecord.WhoId,
                }
            });
            createRecordEvent.fire();
        } else {
            /* Create Record Event is not supported */
            alert("Task creation not supported");
        }
    }
})

Now I have two problems:

- I get error messages if the who or whatid is not populated
- I sometimes get the same error messages​​​​​​ even if the who and whatid is populted
- I actually want to open the component with a quick action button instead of a lightning button (lightning:button and onclick), but I just get a "window in window"

User-added image

Quick Action Error - window in window

Can someone help me please with that probably simple issue? Thanks a lot in advance!
Best Answer chosen by SFDC_Richie
Khan AnasKhan Anas (Salesforce Developers) 
Hi Richard,

Greetings to you!

Currently, Task is not supported in the Lightning Data Service. You can get the list of supported objects from below document.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_considerations.htm

Also, please refer to below link for more information on LDS.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Shubham4462Shubham4462
Hello Richard ,

WhoId is either Lead id or Contact Id so here if you are creating task so you need to pass Lead id and Contact Id in whoId Section , How Can you pass whole object in WhoId as Default value section, if you want it to work pass the Lead Id or ContactId or Either You can Remove the WhoId from this default section .

Thanx Reagds 
Shubham 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Richard,

Greetings to you!

Currently, Task is not supported in the Lightning Data Service. You can get the list of supported objects from below document.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_considerations.htm

Also, please refer to below link for more information on LDS.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
SFDC_RichieSFDC_Richie
Thank you very much for your response! I hope I will resolve that issue in the future.