1

I need to delete all tasks (Activity object) with a Set ownerId.

I noticed that when I write query on Developer Console for getting task records and I can get 10 records, but when I write query on apex class then I just get only task record that related to current user.

I have checked security and I think there are a potential solution is that implement a sharing rule to set edit for a group of user and set Org wide default to private. I am wondering there are any solution for this.

Can anyone give me some advices for this case?

  • do you want anybody to see anybody record ? – Himanshu Nov 26 '15 at 4:21
  • Can you post your code? – Hasantha Nov 26 '15 at 4:40
  • No Himanshu, Task will be created for a group of user. When i login a specific user and i remove the task, and my scenario is that that task will be also disappeared from another user in that group. So i wrote a query on Apex class but it got only one task records that related to current user that login to my web. – Hoang Tran Nov 26 '15 at 4:41
  • It is just simple query @ahtnasah.li. My issue is Salesforce has secured Activity object by some way and I dont know it :(. My query is : [SELECT Id FROM Task WHERE OwnerId IN: listOfUserHaveTask] – Hoang Tran Nov 26 '15 at 4:45
  • 1
    (1) see developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… -- the without sharing should provide access to all Tasks in apex; – cropredy Nov 28 '15 at 1:23
0

Seems like you have declared your class with the 'with sharing' keyword. If you drop that keyword Apex code runs in system context. "In system context, Apex code has access to all objects and fields-object permissions, field-level security, sharing rules aren’t applied for the current user." So if that's the behaviour you looking for then just declare your class as:

public class YourClassName {

// Code here

}
0

You will want to create a class similar to the following:

public without sharing ClassName
{

}

Please ensure to use the "without sharing" keywords as not providing them leaves the class susceptible to inheriting sharing rules from any class that calls it if "with sharing" is defined.

Please see the following document for further details: Using the with sharing or without sharing Keywords

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.