Posts

Showing posts with the label Apex Sharing

Salesforce Apex-based record sharing

Image
In Salesforce, Apex-based record sharing allows you to programmatically share records with users or groups based on specific criteria or conditions. This is useful when you need to dynamically adjust record access beyond what can be achieved through standard sharing settings or manual sharing. Create Apex Sharing Reasons Share Objects and Fields StandardObjectNameShare Example -  Let's say you want to share records with relators who belong to the "Sales" role. Here's an Apex class that uses Apex sharing to share records with users who meet the defined criteria. public class RecordSharingController {          public static void shareRecords() {         // Query records that meet the sharing criteria         List<House__c> recordsToShare = [SELECT Id FROM House__ c WHERE Status__c = 'In Market'];                  // Create a list to hold new sharing objects  ...