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
AndrewTaylorAndrewTaylor 

Lightning Component Task.Type Field is Empty

I have a lightning component which calls an Apex method to initiate a Task:
 
@AuraEnabled
    public static Task initTask(Id contactId) {

        Task t = new Task(
            Type = 'Type A',
            OwnerId = UserInfo.getUserId(),
            Status = 'Completed',
            ActivityDate = Date.today(),
            Priority = 'Normal',
            Subject = 'Notes'
        );
        System.debug('t = ' + t);
        return t;
    }
When I call this, the Type field appears to be empty:
 
var action = component.get("c.initTask");
action.setParams({ 
    "contactId": contactId
});

action.setCallback(this, function(a) {
    var state = a.getState();
    if (state === "SUCCESS") {
        var record 		= a.getReturnValue();
        console.log("record = ");
        console.log(record);
        console.log(record.Type);

        if(record.Type == '') {
            console.log('Type is empty');
        } else {
            console.log('Type is something else?');
        }
        console.log(a.getReturnValue().Type)

        component.set('v.record', record);
        console.log('post set');
        console.log(component.get('v.record').Type);
    } else if (state === "ERROR") {
        var errors = a.getError();
        console.error(errors);
    }
});
$A.enqueueAction(action);

In the log, console.log(record.Type) shows the expected value, however, if I write out {!v.record.Type} in my component, it's empty.

If I reference a different field, it works as expected; my suspicion is that Type is a reserved attribute/parameter, however, I'm unsure of a clean workaround.

Any insights are appreciated.
 

Raj VakatiRaj Vakati
Task Type field is set to Hidden by default.Please check the access 

https://success.salesforce.com/answers?id=9063A000000pJNeQAM
https://help.salesforce.com/articleView?id=000193640&language=en_US&r=https%3A%2F%2Fwww.google.com%2F&type=1
sfdcMonkey.comsfdcMonkey.com
Hey, following example works for me, and the possible suspicion is that javaScript and lightning components are case sensitive so here {!v.record.type} and {!v.record.Type} are 2 different kind of animals, use exect API name of field : [check FLS as well]

working sample :

apex :
public class testGlobalCtrl {
@AuraEnabled
    public static Task initTask(Id contactId) {

        Task t = new Task(
            Type = 'Type A',
            OwnerId = UserInfo.getUserId(),
            Status = 'Completed',
            ActivityDate = Date.today(),
            Priority = 'Normal',
            Subject = 'Notes'
        );
        System.debug('t = ' + t);
        return t;
    }
}

lightning
<aura:component controller="testGlobalCtrl">
    <aura:handler name="init" value="this" action="{!c.doInit}"/>
    <aura:attribute name="record" type="task" default="{'sobjectType' : 'Task'}"/>\
    
	 \this is task type : {!v.record.Type}
    
</aura:component>
 
({
    doInit : function(component, event, helper) {
        var action = component.get("c.initTask");
        action.setParams({ 
            "contactId": '0036F00002O68am' // test id
        });
        
        action.setCallback(this, function(a) {
            var state = a.getState();
            if (state === "SUCCESS") {
                var record 		= a.getReturnValue();
                console.log("record = ");
                console.log(record);
                console.log(record.Type);
                
                if(record.Type == '') {
                    console.log('Type is empty');
                } else {
                    console.log('Type is something else?');
                }
                console.log(a.getReturnValue().Type)
                
               component.set('v.record', record);
                console.log('post set');
               console.log(component.get('v.record').Type);
            } else if (state === "ERROR") {
                var errors = a.getError();
                console.error(errors);
            }
        });
        $A.enqueueAction(action);
    }
})

output :
User-added image

kindly let us know if it helps you
thanks