Questions tagged [apex-sharing]

Granting permission to User/Group of Users via Apex.

Filter by
Sorted by
Tagged with
-5 votes
1 answer
79 views

What is the use of Apex Sharing if we are using permission set

This is interview question and I could not answer
Dheeraj D's user avatar
2 votes
1 answer
277 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://...
Shrivaths Kulkarni's user avatar
0 votes
0 answers
155 views

Sharing of Case Record for Approvers of Approval Process

We are having a Customer Community, and the license used for community users is Customer Community (Not customer community plus). We have built a approval process which will be submitted by the agent ...
Rabb's user avatar
  • 345
0 votes
0 answers
249 views

How to give visibility based on lookup field / related object?

I have a custom object that calls materials and he has a lookup field to a external object, I have access to the external object but the materials record is not visible in related list on experience ...
Alexia's user avatar
  • 73
0 votes
1 answer
238 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 ...
SFGest's user avatar
  • 1
-1 votes
1 answer
36 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.
Gargi Gupta's user avatar
0 votes
1 answer
189 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 ...
Nitish Yadav's user avatar
0 votes
1 answer
268 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( ...
Przemysław Długoszewski-Tamoń's user avatar
-2 votes
1 answer
185 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
Ram's user avatar
  • 1
0 votes
1 answer
45 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 ...
user avatar
0 votes
1 answer
108 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 ...
user avatar
1 vote
0 answers
64 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'...
N_H1922's user avatar
  • 315
3 votes
1 answer
359 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 '...
Kaliforce's user avatar
0 votes
1 answer
329 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??
Shubham's user avatar
0 votes
1 answer
77 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. ...
user91530's user avatar
0 votes
2 answers
47 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(...
priya dhawan's user avatar
3 votes
1 answer
1k 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 ...
Pradip Mohite's user avatar
0 votes
1 answer
848 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 ...
Julien Souchi's user avatar
0 votes
1 answer
105 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 ...
Nagendra Singh's user avatar
0 votes
1 answer
352 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?
user87331's user avatar
0 votes
1 answer
538 views

How to give dynamic record access level using roles?

I have the a role hierarchy like this: manager suboridinate   profiles       profiles ----------- ChildRole1.1 | ...
nSv23's user avatar
  • 524
3 votes
1 answer
1k 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 ...
Mayday's user avatar
  • 65
0 votes
1 answer
405 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 ...
J. Schreiber's user avatar
  • 1,500
0 votes
1 answer
200 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 ...
Suhasini's user avatar
  • 197
0 votes
1 answer
31 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 ...
Giorgos Galaios's user avatar
0 votes
2 answers
998 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?
user12347's user avatar
5 votes
2 answers
999 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()...
nica's user avatar
  • 1,338
0 votes
1 answer
788 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 ...
Json Bourne's user avatar
-1 votes
1 answer
43 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 ...
SFDC's user avatar
  • 658
0 votes
1 answer
996 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?
user12347's user avatar
0 votes
0 answers
398 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 ...
SfdcBat's user avatar
  • 4,751
0 votes
0 answers
459 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 ...
manhnt.bkit's user avatar
0 votes
0 answers
106 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. ...
Brav's user avatar
  • 698
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 ...
Almond's user avatar
  • 3
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 ...
Sisir's user avatar
  • 101
0 votes
0 answers
208 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 ...
Jason Clark's user avatar
  • 11.6k
0 votes
0 answers
350 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 ...
mvk1991's user avatar
  • 525
0 votes
1 answer
137 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 ...
user3456401's user avatar
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 ...
user3456401's user avatar
0 votes
2 answers
3k 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: ...
Dana Griff's user avatar
  • 1,554
1 vote
1 answer
58 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('...
Dana Griff's user avatar
  • 1,554
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 ...
Deepak Agarwal's user avatar
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 ...
Pavan tej's user avatar
  • 1,429
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 ...
Venky's user avatar
  • 634
-1 votes
1 answer
142 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---->'...
Annappa's user avatar
  • 2,312
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 ...
SFDCLearneR's user avatar
14 votes
1 answer
4k 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 ...
Martin Borthiry's user avatar
0 votes
1 answer
3k views

Sharing Case Records with Customer Community Users

We have set up the community in Salesforce and business use case is that whenever the case raises from the external user and assigned it to an internal user for resolution than any action or updates ...
Abhishek Daware's user avatar
2 votes
3 answers
2k views

Apex Based Sharing - Lead Share object

I am working on a requirement to achieve the below: Whenever a lead is created by a user: Check if that user is Rep Type (field present at user level), then add that user to Lead Share object with ...
TheThinkingMan's user avatar
0 votes
1 answer
1k views

How to distinguish manual sharing and apex sharing in code level

I would like to distingish sharing between manual sharing and apex sharing For example please check below code: Code snippet List<Document__Share> lstDocSharesDelete1 = [select Id,...
Annappa's user avatar
  • 2,312