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
jojoforcejojoforce 

retrieving data issue

I have the following code snippet, and for some reason, when the method returns no data, the lightning component aura framework is throwing an error. In desktop, there's no console error message. But in salesforce mobile, the attched error callback getTasks "undefined is not an object evaluating".The other thing to note, in desktop/web, it is not getting to console.log('loadData : c.getTasks AFTER');



Apex Controller
@AuraEnabled
    public static list<Task> getTasks(String selectedFilter){


        Id currentUserId = userinfo.getUserId();
        set<Id> teamMemberIDs = new set<Id>();

        list<Task> tasks = new list<Task> ();

        teamMemberIDs.add(currentUserId);
        for(User u : [SELECT Id,ManagerId FROM User WHERE ManagerId = :currentUserId]){
            teamMemberIDs.add(u.Id);
        }

        String strQuery = ' SELECT Id, Who.Name, What.Name, AccountId,Account.Name,Subject,Status,Priority,OwnerId,Owner.Name ';
        strQuery += ' FROM Task ';
        strQuery += ' WHERE IsClosed = FALSE ';

        if(selectedFilter == 'TodayTasks'){
            strQuery += ' AND ActivityDate = TODAY ';
            strQuery += ' AND OwnerId = \'' + currentUserId + '\'';

        } else if (selectedFilter == 'AllOverdueTasks') {
            strQuery += ' AND ActivityDate < TODAY ';
            strQuery += ' AND OwnerId = \'' + currentUserId + '\'';
        } else if (selectedFilter == 'TomorrowsTask') {
            strQuery += ' AND ActivityDate = TOMORROW ';
            strQuery += ' AND OwnerId = \'' + currentUserId + '\'';

        } else if (selectedFilter == 'MyTeamsTasks') {            
            strQuery += ' AND ActivityDate = TODAY ';
            strQuery += ' AND  OwnerId IN :teamMemberIDs ';            
        }

        strQuery += ' ORDER BY Subject ASC, What.Name ASC ';
        //strQuery += ' LIMIT 6 ';

        System.debug('JOSEPH DEBUG: getTasks selectedFilter ' + selectedFilter);
        System.debug('JOSEPH DEBUG: getTasks strQuery : ' + strQuery);

        tasks = Database.query(strQuery); 
        return tasks;
    }
Aura Bundle Javascript Controller
({
    callServer : function(component,method,callback,params) {
        var action = component.get(method);
        if (params) {
            action.setParams(params);
        }      
        action.setCallback(this,function(response) {
            var state = response.getState();
            if (state === "SUCCESS") { 
                // pass returned value to callback function
                callback.call(this,response.getReturnValue());   
            } else if (state === "ERROR") {
                // generic error handler
                var errors = response.getError();
                if (errors) {
                    console.log("Errors", errors);
                    if (errors[0] && errors[0].message) {
                        throw new Error("Error" + errors[0].message);
                    }
                } else {
                    throw new Error("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },
    loadData : function(component) {
        console.log('loadData : ' +  component.get("v.selectedFilter"));
    
        //Get Task Records
        this.callServer(component,"c.getTasks",function(response){
            console.log('loadData : c.getTasks BEFORE');
            component.set("v.tasksCount", response.length);   
            console.log('loadData : v.tasksCount response.length ' + response.length);
            if(response.length > 0){
                component.set("v.isThereTasks",true);
                component.set("v.tasks", response);  
    
            } else {
                component.set("v.isThereTasks",false);
            }
            console.log('loadData : c.getTasks AFTER');

        },{
            selectedFilter: component.get("v.selectedFilter")               
        }); 
    }
    
});
Aura Bundle Component
<aura:attribute name="tasks" type="Task[]"/>

 
Best Answer chosen by jojoforce
jojoforcejojoforce
I figured it out. I had put a tag in the lightning:input that wasn't supported or the aura framework does not like data-taskid="{!task.Id}"

After removing the tag in the lightning:input, it is now working!

 
<tbody>
                        <aura:iteration items="{! v.tasks }" var="task">
                            <tr class="slds-hint-parent">
                                <td class="slds-text-align_left" style="width:30px;">
                                    <lightning:input type="checkbox" label="Checkbox Label" variant="label-hidden" name="{!task.Id}" onchange="{! c.handleCloseTask }" data-taskid="{!task.Id}"></lightning:input>
                                </td>
                                <td class="slds-text-align_left">
                                    <!--
                                    <div class="slds-grid slds-truncate_container_33"  >
                                        <a target="_blank" class="slds-text-link slds-truncate" title="{!task.Subject}" href="" onclick="{! c.handleTaskLink }" data-taskid="{!task.Id}">
                                            {!task.Subject} 
                                        </a>            
                                    </div>
                                    -->
                                    <div class="slds-truncate" title="{!task.Subject}">
                                        <a target="_blank" class="slds-text-link slds-truncate" title="{!task.Subject}" href="" onclick="{! c.handleTaskLink }" data-taskid="{!task.Id}">
                                            {!task.Subject} 
                                        </a>            

                                    </div>

                                </td>
                                <td class="slds-text-align_right">

                                    <div class="slds-truncate" title="{!task.Account.Name}">
                                        <a target="_blank" class="slds-text-link slds-truncate" title="{!task.Account.Name}" href="" onclick="{! c.handleAccountLink }" data-accountid="{!task.AccountId}">
                                            {!task.Account.Name}
                                        </a>        
                                    </div>
                                </td>
                            </tr>
                        
                        </aura:iteration>
    
                    </tbody>