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
Paul Grice 20Paul Grice 20 

apex SOQL returns empty list in SF1 (but works in Lightning Experience)

I am calling an SOQL query in an apex server class. It returns 2 records in the Lightning Experience in the browser but an empty list in Salesforce1 on the mobile. If I create and return a list it works, so it seems to be the query which is the problem. The user is the same in both instances. (I'm also not really sure how to generate a debug log for mobile.)

APEX controller
public with sharing class TaskController {
    @AuraEnabled
    public static List<Task> getTasksforContact(String id) {
        List<Task> t = new List <Task>();
        t = [ SELECT Id FROM Task WHERE WhoId = '0035B000008mEwa' ];

// test
/*
         Task t2 = new Task(WhoId = '0035B000008mEwa', Subject = 'Test');
        List<Task> t = new List<Task>();
        t.add(t2);
*/       
        return t;
    }
Client Controller
({
	doInit : function(cmp) {
                      
        var action = cmp.get ("c.getTasksforContact");
        var theId = cmp.get("v.contactId");
        theId = "0035B000008mEwa"; // testing
        
        action.setParams ({ id : theId });
        
        action.setCallback(this, function(response) {
            var state = response.getState();        
       
            if (state === "SUCCESS") {
                var retVal = response.getReturnValue();
                cmp.set ("v.tasks", retVal);
                var t = cmp.get("v.tasks");                
            }
            else
                console.log("State is NOT Success!");
        });
        $A.enqueueAction(action);        
    }
})
Client Component
<aura:component controller="TaskController" 
                implements="flexipage:availableForAllPageTypes" >
    
    <aura:attribute name="contact" type="Contact" />
    <aura:attribute name="contactId" type="String" />
    <aura:attribute name="leadId" type="String" />
    <aura:attribute name="tasks" type="Task[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:method name="refresh" action="{!c.doInit}" />
    
    <aura:iteration items="{!v.tasks}" var="task">
        Subitem<br />
        {!task.Id}<br /> {!task.Subject}<br /> 
    </aura:iteration>
    
</aura:component>

 
Paul Grice 20Paul Grice 20
The component is included on a custom contact page like this:
<c:ContactTaskList contactId="{!v.recordId}" aura:id="cmpTaskList" />
In case it were a timing issue, I also refresh the component from the doInit() but in both cases it returns empty. The component seems to be loading since a static text in the component displays on the contact page.
The contact page overloading is done through Setup > Customise . Contacts > Buttons, Links and Actions > View/Edit.
 
Paul Grice 20Paul Grice 20
For testing in the browser I used the App Builder to embed my Contact Page detail page in a Lightning App.
Paul Grice 20Paul Grice 20
Oops. In the end it seems to be a simple permissions issue. I was not looking from the same user login, it was working for a supervisor. And the two tasks were not assigned to the partner user, hence he couldn't see them. At first I removed the "WHERE" from the query, which showed some results, so it was not an overall problem accessing the Tasks object. Then reassigning the tasks to the test partner user made them show with the "WHERE" reinstated. Thanks your help and interest anyway.