0

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]; 

1 Answer 1

1

it prints false

For me it prints true, I'm a full System Administrator. There must be something with your Profile or Permission Sets.

how come its showing user doesn't have permission to access task but if we remove this code it works fine

Because Apex on it's own works in system mode, skipping the object and field-permission checks unless you enforce them WITH USER_MODE, SECURITY_ENFORCED, isAccessible(), stripInaccessible() etc. This is about access to whole tables and columns in them which is separate from row-level access (with sharing)

Do you have "Access Activities" or "Edit Tasks" checkboxes?

What do you get when you run this

SELECT Name, Profile.Name, PermissionsActivitiesAccess, PermissionsEditTask 
FROM PermissionSet 
WHERE Id IN (SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId = 'put your user id')
Sign up to request clarification or add additional context in comments.

1 Comment

I was running for community user and checking boxes for Access activities and edit tasks under system permissions worked for me. Thanks @eyescream

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.