Questions tagged [apex-sharing]
Granting permission to User/Group of Users via Apex.
107
questions
0
votes
1
answer
24
views
Error on OpportunityShare records
I have written an Apex Sharing class, I need to share the Opportunities to the users who has the Same role as Opportunity Owner in the Org, and this is not for the entire Org Only for few roles, the ...
-1
votes
1
answer
52
views
With Sharing and Without Sharing scenario
I have recently started learning about apex security. I have one scenario where I'm not able to tell the exact outcome even after going through a lot of articles and youtube videos.
Scenario: When '...
3
votes
1
answer
271
views
Can't delete Apex class from production, deployment fails with "This Batchable class is in use. : Apex Sharing Recalculation", but no job queued?
I created a batch class to update some records a few days ago, and ran it on the same day. I left the class in production, unused, so I could delete it when I had some time to spare.
When I proceeded ...
0
votes
0
answers
139
views
Apex sharing: INVALID_FIELD_FOR_INSERT_UPDATE, Visibility InternalUsers is not permitted for this linked record
I am working on a trigger helper whose requirements are:
If a file is shared to certain custom objects that are descendants of the Account, share that file to the Account as well
Based on the value ...
0
votes
1
answer
190
views
Campaign Member Sharing Rules
I need to create a Sharing Rule that only allows Users to see Campaign Members where they are the record owner of the Contact or Lead that corresponds with the Campaign Member.
Sharing Rules don't ...
-5
votes
1
answer
324
views
What is the use of Apex Sharing if we are using permission set
This is interview question and I could not answer
2
votes
1
answer
614
views
share folders using apex
Looking for a feature(apex) to share folders to users/groups etc using apex. We have REST based APIs to do. Just wondering if we have anything like that in Apex.
Following are working fine:
https://...
0
votes
1
answer
780
views
How to check in Apex if a user has sharings to a given record?
I have an ID of a user (let's say 'id_1111111111') and I have an ID ('id_2222222222') of a record of a custom object Job__c.
How can I check in Apex / SOQL if the user with id 'id_1111111111' has ...
-1
votes
1
answer
59
views
What happens when a record is shared programmatically and granted 'Read' access but organization wide default is private? [closed]
What happens - If I create a record programmatically using apex with AccessLevel = 'Read' but OWD is set to private for that Object.
0
votes
1
answer
359
views
Changing Case Owner in With sharing class
I have few question on "with Sharing" and "without Sharing" keyword in apex,
In my Org the OWD for case is Public read only. I have one class where i am updating owner id of the ...
0
votes
1
answer
371
views
Is it possible to share OpportunityTeamMember records via Apex?
I would like to share OpportunityTeamMember records via the Apex Sharing feature. I could not run the following code, though:
<OpportunityTeamMemberShare otms = new OpportunityTeamMemberShare(
...
-2
votes
1
answer
271
views
How to get the List<Lead> from List<LeadShare> in apex [closed]
Map<String, List<LeadShare>> UserLeadShareMapVal = new Map<String, List<LeadShare>>();
How to convert the above Map to
Map<String, List<Lead>> UserLeadMapVal
0
votes
1
answer
60
views
Limit Sharing to only one User Id?
I am working on apex sharing and having trouble making it so only a single share record is allowed per Team Member. Here you can see there are 2 of the exact same Team Members with varying access ...
0
votes
1
answer
127
views
Alter code to be reusable across objects?
I'm working on this https://medium.com/salesforce-zolo/build-your-own-teams-feature-for-custom-objects-in-salesforce-963ed3630f4 but trying to instead alter it into a single helper class that creates ...
1
vote
0
answers
97
views
How to handle data skew when working with partner portal?
I have a very simple use case where I have a few partner accounts to which I assign cases. Under each account I have 5-10 partner users who need access to all the cases assigned to the account. So I'...
3
votes
1
answer
488
views
Why does Apex sharing custom object only work with UserID and not GroupID?
Requirement: I want to be able to have private OWD on the objects and share its access to groups/queue.
What works:
I'm able to Apex share records to a queue to a vendor packaged object '...
0
votes
1
answer
416
views
Organisation Wide Default and Sharing Rule and Apex Sharing
If organisation wide default is read write and record is shared in read mode by sharing rule or by apex then which will be the final access to the user??
0
votes
1
answer
132
views
Class declared as With Sharing then why Permission check?
Can anyone please explain if the class is declared as With Sharing then why do we still need to check if the User has permission for SOQL or not or the object creatable/editable etc? Please clarify. ...
0
votes
2
answers
50
views
how to optimize apex sharing trigger
Hi I want to write a trigger on my custom object salesOrder__c whenever a record is inserted it has lookup to account (Sold_to_Party__c) I want to share sales Orders with all its accounts team members(...
3
votes
1
answer
2k
views
Apex Sharing - With Sharing Batch class execute from object trigger
From Apex trigger the batch class is executed which has With Sharing keyword. And inside the Batch class, there is a record delete statement without a CRUD check. Currently, a user who doesn't have ...
0
votes
1
answer
1k
views
AccountContactRelation and child custom objects. Sharing behavior
I'm using AccountContactRelation to give access to some accounts to my community users.
It's working great in this regard.
but the thing is, i got a custom "Contrat" object that is a child ...
0
votes
1
answer
149
views
Changing owner vs creating Share record via Share record or Group
Scenario : Account and Contact both are private for external users.
A user (A) from community creates a new contact and an email is triggered to the contact for registration flow.
The registration ...
0
votes
1
answer
468
views
Class with sharing get access just to records from the current user?
Need to update related records based in a field value from the parent record. If I use with sharing in class, just the records that the current user has access will be updated?
0
votes
1
answer
676
views
How to give dynamic record access level using roles?
I have the a role hierarchy like this:
manager suboridinate
profiles profiles
----------- ChildRole1.1
|
...
3
votes
1
answer
2k
views
Manual Sharing Rules Mysteriously Removed
We also have an issue where Salesforce Support hasn't been a lot of help. We have some Apex code that was developed by a Salesforce contractor. We have a custom object and we have Apex code making a ...
0
votes
1
answer
519
views
Apex "Manual" Sharing on Standard Object (Account): Sharing Gets Deleted
We use a Customer Community to dispatch Work Orders to partners. The partners use Customer Community Plus licenses. We share the Work Order using a community sharing set, but we cannot share the ...
0
votes
1
answer
355
views
Creating share record based on recordId dynamically
I am working on a scenario of creating generic apex method of creating share records by using the recordId of an Object. I have a method which accepts recordId, userId, levelOfAccess and sharingReason ...
0
votes
1
answer
38
views
Field Updateable on Create but Read Only on edit
I have a custom field on account object (Id number). I want a custom profile's users to be able to:
On new account insert id number
On edit i want this field to be read only, so as users of these ...
0
votes
2
answers
1k
views
Apex records sharing vs standard record sharing
I need to know what are the advantages of the Apex records sharing compared to the standard record sharing with sharing rules?
When to use Apex records sharing over the standard record sharing?
5
votes
2
answers
1k
views
Apex class to be used for both with and without sharing
I have created a selector class on Campaign object to be used in with sharing context like below:
public with sharing class CampaignSelector {
public static Map<Id, Campaign> getCampaigns()...
0
votes
1
answer
935
views
Apex bulk sharing Batch class
I came across a new feature on Salesforce apex sharing where you can define a batch class and can associate that batch class to an Object. Whenever security settings changes for the object the batch ...
-1
votes
1
answer
52
views
Overcoming sharing settings
I have a Owd for account object is Public read only.I want to give Public read/write access for particular profile using Apex code.Is it possible withsharing Keyword?If it possible please give some ...
0
votes
1
answer
1k
views
Apex managed sharing limits?
I've implemented a User Managed Sharing Using Apex and need to know are there any limits for Apex User Managed Sharing for standard or for custom objects?
0
votes
0
answers
469
views
system runAs method to verify if the user can access a record
I have below test class which verifies whether a use have access to the record or not. The Campaign__C object's sharing setting is Private. However with below test class when I run the SOQL the 2nd ...
0
votes
0
answers
502
views
isUpdateable method return false on without sharing class
I having a visualforce page with a controller(without sharing)
I have tried both method:
- Schema.sObjectType.Opportunity.isUpdateable()
- Schema.DescribeSObjectResult - isUpdateable()
Both of them ...
0
votes
0
answers
140
views
SharingRule is not being shown as RowCause in OpportunityShare record
I have granted a User access to an Opportunity record through an Opportunity sharing rule. Now I can see in the UserRecordAccess Object that the User has access to this particular Opportunity record. ...
0
votes
1
answer
2k
views
SFDX: How to pull SharingRules from scratch org to local?
I changed the CustomObject__c OWD to Private. I created a sharing rule through Apex trigger.
When I pulled it, it only pulls the Trigger, Class, and CustomObject__c.meta BUT no sharingRule xml.
That's ...
1
vote
1
answer
2k
views
Using without sharing methods inside with sharing class (with sharing applied)
I have a controller ControllerClassA which is with sharing. And i also have another class HelperClassB which is without sharing. I have a method inside a without sharing class HelperClassB which is ...
0
votes
0
answers
234
views
Apex Managed Sharing fails sharing Case with Community Plus user
Scenario: A 'Customer Community' License user logs into a community and creates a case, which is automatically assigned to a queue. A trigger on case invokes a future method (of a class declared ...
0
votes
0
answers
419
views
Apex Sharing : AccountShare ImplicitParent
I am querying below AccountShare records -
Select Id,AccountAccessLevel,Account.Name,RowCause,UserOrGroupId from AccountShare where UserOrGroupId='some_id'
I am getting 2 records in which ...
0
votes
1
answer
157
views
Lightning DataTable with CaseShare - Returning User or Group Name
I am using the lightning datatable in order to display the CaseShare data for a Case record within a lightning component. The feature works great however as the field UserOrGroupId on the CaseShare ...
2
votes
2
answers
2k
views
Trigger on Custom Object Share
I have a requirement whereby once a custom object record is created I must share this with AllInternalUsers. I have written a trigger on after insert to the custom object that this share record will ...
0
votes
2
answers
4k
views
Insufficient Access Right on "Without Sharing" Class
I'm trying to insert Sharing records via apex for the object "SBQQ__Quote__Share".
The class that inserts the record uses "without sharing", but when i to insert the record i receive the error:
...
1
vote
1
answer
79
views
Generic return for function
I have the following function that creates a share to a custom object:
public static Order_Request__Share generateOrderRequestShare(Id orderRequestID, Id userId, Boolean readOnly){
System.debug('...
0
votes
0
answers
2k
views
Sharing records through apex with Public Group
I am sharing Opportunity records through OpportunityShare from Apex with Public Groups. When i checked the sharing button the record is being shared with that Group but after logging in as that user ...
0
votes
0
answers
3k
views
TooManyLockFailure : Too many lock failure 200 Trying again later
I have a requirement to provide a particular group of records to one user.But record sharing criteria depends on formula field.
So, I'm not able to share through sharing rules. So, I have created an ...
1
vote
2
answers
2k
views
User unable to edit created Contract
OWD for Account and Contract is Public Read-Only.
As we know that Account and Contract have Master-Detail relationship. Whenever a user creates Contract record the owner of the record is being ...
-1
votes
1
answer
185
views
Default external access Setting Issue for site Guest user
If I query this record I will get one record
Query Editor & Anonymous window
select id,Name from Account where Name='TestPartner'
but In coding,
system.debug('company domain---->'...
4
votes
1
answer
2k
views
For which scenario we need to use apex managed sharing?
We can control access to data at many different levels (OWD, Sharing Rule, Role Hierarchies) in salesforce. However, in which case we need to use apex managed sharing? Can you please explain with ...
14
votes
1
answer
5k
views
Schedule and Run a Report as an specific User from Apex
Background
What we are trying to accomplish is to run daily some specific reports as an specific user.
So far
From a lightning component we are allowing the user to select a reports list. Once the ...