+ Start a Discussion
Jonathan Wolff 7Jonathan Wolff 7 

Error by using Who.Name of tasks in datatable

Hello friends, I have a task datatable component and added the Who.Name as a column. the problem is, that now I do get error messages whenever there is a task where Who.Name is empty. Could you give me a solution for it?

User-added image
My code:

APEX
@AuraEnabled
public static List<Task> loadTasks3(Id recordId){
    string userId = UserInfo.getUserId();
    return[SELECT Subject, Who.Name, ActivityDate, Status FROM Task WHERE ActivityDate = TOMORROW AND OwnerId=:userId AND Status !='Completed'];
}



JS
component.set('v.mycolumns', [
            {label: 'Thema', fieldName: 'SubjectName', type: 'url',
            typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
                 {label: 'Name', fieldName: 'whoName', type: 'text',
            typeAttributes: {label: { fieldName: 'Who.Name' }, target: '_blank'}},
        ]);
        var action = component.get("c.loadTasks");
            action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
                records.forEach(function(record){
                   
                    record.SubjectName = '/'+record.Id;
                    record.whoName = record.Who.Name
                });
                component.set("v.tasks", records);
            }
        });
        $A.enqueueAction(action);

 
Best Answer chosen by Jonathan Wolff 7
Suraj Tripathi 47Suraj Tripathi 47
Jonathan,
As I can clearly see that you have a parameter named recordId in your apex method (loadTasks) ,  but you have not included the parameter in your js controller. You can remove a parameter from your apex method, as I can see there is no use of that. You can refer to the below apex method :
 
@AuraEnabled
public static List<Task> loadTasks(){
    string userId = UserInfo.getUserId();
    return[SELECT Subject, Who.Name, WhoId, ActivityDate, Status FROM Task WHERE ActivityDate< TODAY AND OwnerId=:userId AND Status !='Completed'];
}
Please mark it as the best answer, if it solves your problem

Thanks and Regards
Suraj Tripathi

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi Jonathan,
I reviewed your error message that you have shared and I came up with these solutions:
  • I found the apex method you shared is named loadTasks3 , but in the js controller you are calling loadTasks .
  • You are also not providing parameter to the apex method in your js controller.
Please try these above solutions and if it solves your query , please mark it as the best answer .

Thanks and Regards
Suraj Tripathi
Jonathan Wolff 7Jonathan Wolff 7
Hi, I have several @AuraEnabled parts in the apex, i took the wrong one. there is also the same code for loadTasks :)

Could you elaborate what you mean with providing parameters to js controller?

Greetings,
Jonathan
Suraj Tripathi 47Suraj Tripathi 47
Hi Jonathan,
Could you please provide me the Apex method for 'loadTasks'.
Moreover, If you are passing parameters in apex method, then you also need to set parameters in js controller too.

Thanks and Regards
Suraj Tripathi
 
Jonathan Wolff 7Jonathan Wolff 7
Hi Suraj, sure :D
 
@AuraEnabled
public static List<Task> loadTasks(Id recordId){
    string userId = UserInfo.getUserId();
    return[SELECT Subject, Who.Name, WhoId, ActivityDate, Status FROM Task WHERE ActivityDate< TODAY AND OwnerId=:userId AND Status !='Completed'];
}
 
component.set('v.mycolumns', [
            {label: 'Thema', fieldName: 'SubjectName', type: 'url',
            typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
                {label: 'Name', fieldName: 'whoName', type: 'text',
            typeAttributes: {label: { fieldName: 'Who.Name' }, target: '_blank'}}, 
        ]);
        var action = component.get("c.loadTasks");
            action.setCallback(this, function(response){ 1
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
                records.forEach(function(record){
                   
                    record.SubjectName = '/'+record.Id;
                    record.whoName = record.Who.Name

                                    	
                });
                component.set("v.tasks", records);
            }
        });
        $A.enqueueAction(action);

 
Suraj Tripathi 47Suraj Tripathi 47
Jonathan,
As I can clearly see that you have a parameter named recordId in your apex method (loadTasks) ,  but you have not included the parameter in your js controller. You can remove a parameter from your apex method, as I can see there is no use of that. You can refer to the below apex method :
 
@AuraEnabled
public static List<Task> loadTasks(){
    string userId = UserInfo.getUserId();
    return[SELECT Subject, Who.Name, WhoId, ActivityDate, Status FROM Task WHERE ActivityDate< TODAY AND OwnerId=:userId AND Status !='Completed'];
}
Please mark it as the best answer, if it solves your problem

Thanks and Regards
Suraj Tripathi
This was selected as the best answer