Questions tagged [without-sharing]

Use the with sharing or without sharing keywords on a class to specify whether or not to enforce sharing rules.

Filter by
Sorted by
Tagged with
0 votes
1 answer
41 views

Identify in which mode(System/User mode) the class is running

From the Salesforce security review point of view for the the app exchange app, we need to add the access checks while querying and doing DML operations. If we have a requirement that the SOQL/DML ...
user avatar
2 votes
1 answer
86 views

Inner Class Without Sharing not working as expected

I found this post (Sharing rules and Inner classes), which references documentation that inner classes do not inherit the sharing of their container class. From the documentation: Both inner classes ...
user avatar
2 votes
1 answer
49 views

Classes with no sharing declaration don't behave the same as those "without sharing"

I had been under the impression that omitting a sharing declaration was equivalent to using "without sharing", but that appears to not always be true. For example, if I have legacy code like ...
user avatar
0 votes
1 answer
205 views

is omitted sharing in a class the same as with sharing?

I am bit confused about with sharing and without sharing in Apex. I have set OWD to private for Contacts and created sharing rules. If I login as an Admin, I see all the contacts. If I login with a ...
user avatar
  • 466
1 vote
1 answer
566 views

Public VF page with a controller having “Without Sharing” is failing to update the record with Summer'20 Guest User Security Policy Enforced on org

I am working on a customer requirement POC where I would like to allow external users to update the record form any standard/custom object. In order to achieve this, I set up a public site/community ...
user avatar
0 votes
2 answers
190 views

Without Sharing class failed on validation rule

Custom apex trigger initiates a change on opportunity(from within a without sharing static class). Which than apply DML update operation. Validation rule fails on opportunity. The validation rule ...
user avatar
12 votes
2 answers
409 views

Clean way to vary sharing at runtime in Apex?

I may need to make many @RestResource Apex classes run either with sharing or without sharing where that option is selected at runtime. But this approach (that I am using at present): /** * Allow ...
user avatar
  • 131k
3 votes
2 answers
200 views

with and without sharing with innerclass

I'm working on a project that needs to change a lot of data that the user shouldn't see in the backoffice. So I'm wondering if I should put my entire class "without sharing". For now I'm creating a "...
user avatar
1 vote
2 answers
517 views

Using Without Sharing apex class in a Managed Pacakge

Can we use Without sharing class in a managed package? We have a scenario where we want to query recent activities of Account, Contact and Opportunity and Custom_Object__c whenever we receive an ...
user avatar
  • 10.9k
1 vote
2 answers
510 views

User hits record lock error despite class without sharing

My users keep hitting a record lock error despite the class being defined as without sharing. My understanding is that without sharing allows locked records to be edited by any user. This class is the ...
user avatar
0 votes
1 answer
45 views

how to call with inherited class in parent class

below is the code what i am trying is to fetch contact record in without sharing mode. commented part has the problem and it showing Method does not exist or incorrect signature: void ...
user avatar
  • 1,298
0 votes
1 answer
181 views

Component Error - access rights?

I have a Lightning component that works correctly when logged in as a SysAdmin. However, when logged in as a user with a different profile, the error below is received. I have without sharing set in ...
user avatar
4 votes
1 answer
304 views

How do I find out if a field is updateable by the System?

I am running a batch process that is marked without sharing. I would like to to take one course of action if the batch process can update a particular field, and another if not. For example: if (...
user avatar
0 votes
1 answer
3k views

INVALID_CROSS_REFERENCE_KEY: Record Type ID: this ID value isn't valid for the user: (RecordTypeId)

I do know that we can use "without sharing" when we dont want to apply the sharing rules of the current user to set the values, but my class has nothing after access modifiers, just public class ...
user avatar
1 vote
1 answer
340 views

`sharing` / `without sharing` keywords inheritance behaviour

I have a doubt regarding sharing mechanism in Salesforce. If we have these classes: public without sharing class Ctrl1 { } public with sharing class Ctrl2 extends Ctrl1 { } By reading the ...
user avatar
0 votes
1 answer
119 views

Not able to access CronJobDetail object when class is With sharing mode

I am not able to access CronJobDetail object when my class is in with sharing mode. Getting the below error: sObject type 'CronJobDetail' is not supported. Any idea? Thanks!
user avatar
  • 71
15 votes
3 answers
2k views

What's It Called: Inner Class Without Sharing?

I believe I have heard a specific term for this pattern, but I am not able to retrieve it from the foggy banks of my memory: public with sharing class OuterClass { public without sharing class ...
user avatar
  • 144k