I have Task object where we have stored data, I am trying to retrieve data using SOQL query, in order to pass PMD analysis I have access check like this before SOQL query
if (!Schema.sObjectType.Task.isAccessible()) {
throw new AuraHandledException('Insufficient access to Task records.'); }
It throws an exception, if I comment this if condition then it works fine. How can I have this check? User has access to its parent object but we want to place check. I already tried SOQL query ending "WITH USER_MODE or WITH SECURITY_ENFORCED" but results are same its failing. I also used debug statement:
System.debug(Schema.sObjectType.Task.isAccessible());
it prints false. how come its showing user doesn't have permission to access task but if we remove this code it works fine.
SOQL Query we are using:
List<Task> tasks = [SELECT Id, Description FROM Task WHERE WhatId = :Id AND Subject = 'My Data' LIMIT 1];