Questions tagged [apex-sharing]

Granting permission to User/Group of Users via Apex.

Filter by
Sorted by
Tagged with
0 votes
1 answer
22 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( ...
user avatar
-2 votes
1 answer
30 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
user avatar
  • 1
0 votes
1 answer
23 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
  • 3
0 votes
1 answer
30 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
  • 3
1 vote
0 answers
18 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'...
user avatar
  • 155
3 votes
1 answer
37 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 '...
user avatar
0 votes
1 answer
41 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??
user avatar
0 votes
1 answer
26 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. ...
user avatar
0 votes
2 answers
39 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(...
user avatar
3 votes
1 answer
335 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 ...
user avatar
0 votes
1 answer
344 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 ...
user avatar
0 votes
1 answer
39 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 ...
user avatar
0 votes
1 answer
104 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?
user avatar
0 votes
1 answer
247 views

How to give dynamic record access level using roles?

I have the a role hierarchy like this: manager suboridinate   profiles       profiles ----------- ChildRole1.1 | ...
user avatar
  • 456
3 votes
1 answer
598 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 ...
user avatar
  • 55
0 votes
1 answer
248 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 ...
user avatar
  • 1,330
0 votes
1 answer
68 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 ...
user avatar
  • 167
0 votes
1 answer
26 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 ...
user avatar
0 votes
2 answers
508 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?
user avatar
5 votes
2 answers
415 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()...
user avatar
  • 1,232
0 votes
1 answer
472 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 ...
user avatar
-1 votes
1 answer
27 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 ...
user avatar
  • 648
0 votes
1 answer
595 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?
user avatar
0 votes
0 answers
185 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 ...
user avatar
  • 4,521
0 votes
0 answers
285 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 ...
user avatar
0 votes
0 answers
48 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. ...
user avatar
  • 718
0 votes
1 answer
854 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 ...
user avatar
  • 3
0 votes
1 answer
1k 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 ...
user avatar
  • 91
0 votes
0 answers
118 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 ...
user avatar
  • 10.9k
0 votes
0 answers
233 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 ...
user avatar
  • 497
0 votes
1 answer
107 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 ...
user avatar
2 votes
2 answers
926 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 ...
user avatar
0 votes
2 answers
2k 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: ...
user avatar
  • 1,494
1 vote
1 answer
31 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('...
user avatar
  • 1,494
0 votes
0 answers
1k 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 ...
user avatar
0 votes
0 answers
2k 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 ...
user avatar
  • 1,420
1 vote
2 answers
1k 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 ...
user avatar
  • 604
-1 votes
1 answer
75 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---->'...
user avatar
  • 2,264
3 votes
1 answer
1k 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 ...
user avatar
13 votes
1 answer
3k 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 ...
user avatar
0 votes
1 answer
1k 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 ...
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 ...
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,...
user avatar
  • 2,264
1 vote
0 answers
131 views

Community Sharing set field mapping

I am trying to work with Community sets and I am facing the following issues. I had created some sharing User:Contact = Case:Parent.Some_Lookup_Field__c and records were successfully shared I changed ...
user avatar
  • 1,071
1 vote
1 answer
416 views

Finding sharing settings on custom objects

I want to know on custom object what is the sharing setting whether is Private, Public or Public/Read/Write. I have looked at the sharing table like CustomObject__Share SELECT Id,ParentId,...
user avatar
  • 6,559
1 vote
1 answer
557 views

Share Pricebook record to the current user using Apex trigger or class or Flow

If there any Option to share the newly created Pricebook using Apex class to Current user. We have separate object(Opportunity Share) for Opportunity sharing like that do we have any object to share ...
user avatar
0 votes
0 answers
226 views

How the Custom Apex Sharing works in salesforce?

In my org, Case OWD is Private and Case has two child objects (Transaction1 and Transaction2) whose OWD is Private too. Transaction-1 and Transaction-2 object has lookup relationship with Case. I ...
user avatar
  • 161
1 vote
1 answer
52 views

Fate of unsupported Lightning features?

Has Salesforce has said anything (officially or unofficially) about whether or not Lightning will support the below features that currently you have to switch back to Classic to manage? I have not ...
user avatar
  • 11.1k
0 votes
2 answers
141 views

Give access read/write to child object when owner changes old to new in salesforce?

I have a Case Object, P1 and P2. P1 and P2 has an lookup relationship with Case. The moment Case owner changes, original case creator should get the Read access on Case and P1 and P2 object. In OWD, ...
user avatar
  • 169
0 votes
1 answer
1k views

how to share a record to particular user

there is a lookup field with User object UserLookup__c : when the field is not empty , share that particular record to selected user in the lookup field. how can we achieve this 1. I think we can ...
user avatar