0

When I apply CRUD FLS to submit my code for code scanner my class business logic is not working even though I have given all access to task and activity object.

Class is rest resource class and is accessible from site. Following is the block of code where I am applying CRUD FLS:-

String contactId = {!recordId};
if(Schema.sObjectType.Task.fields.whoId.isCreateable()){
     Task t1 = new Task();
     t1.whoId = contactId;
}
if(Task.sObjectType.getDescribe().isCreateable()){
     insert t1;
}
1

You are declaring your task object inside if block

if(Schema.sObjectType.Task.fields.whoId.isCreateable()){
     Task t1 = new Task();
     t1.whoId = contactId;
}

It will not be available when compiler will move ahead to execute this block

if(Task.sObjectType.getDescribe().isCreateable()){
     insert t1;
}

it will give you error Variable does not exist: t1

How did it even allow you to Save your class ? I am surprised

you need to declare Task t1 = new Task(); outside if block so that t1 will be accessible here

if(Task.sObjectType.getDescribe().isCreateable()){
         insert t1;
}
  • Even if apply CRUD on task fields and access are provided then also not working and returning false in IF. Is this the right way to do? for (Task objTask : taskList){ if(Schema.SObjectType.Task.fields.Message_Status__c.isAccessible() || Schema.sObjectType.Task.fields.Message_Status__c.isUpdateable()) objTask.Message_Status__c = taskStatus; } } – Vinod Jul 4 '18 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.