0

I have created share object in my salesforce environment. From Setup-> security Controls -> Sharing Settings -> I made my custom object access to "Private". So suppose my object name is EVT_Client__c & I am trying to insert data into EVT_Client__Share from trigger(AfterInsert) I am unable to do it. I am getting error as given below.

Once data get inserted into EVT_Client__c object our trigger tries to insert data into EVT_Client__share object but we are getting error. Profile user who is inserting data into EVT_Client__c object through UI having Read/create/edit/delete access on object.

System.TypeException: DML operation INSERT not allowed on EVT_Client__Share

My code in trigger is as below in which I am getting error.

public with sharing class EVT_Client_Assessment_TriggerHandler {
          private void ShareClientToThirdPartyJobGroup(List<EVT_Client__c> lstClients){
        List<EVT_Client__Share> lstSharesForThirdPartyGroup = new List<EVT_Client__Share>();
        List<Group> lstThirdPartyGroups = [Select Id, RelatedId from Group where Name = 'Third Party'];

        for(EVT_Client__c client: lstClients){
            for(Group roleGroup : lstThirdPartyGroups ){
                  EVT_Client___Share objShareForThirdPartyGroup = new EVT_Client__Share(ParentId = client.Id, 
                      UserOrGroupId = roleGroup.Id, 
                      AccessLevel = 'Edit', 
                      RowCause = Schema.EVT_Client__Share.RowCause.User_Client__Access__c);
              lstSharesForThirdPartyGroup.add(objShareForThirdPartyGroup);
            }   
        }

        insert lstSharesForThirdPartyGroup;
    }
    }
4
  • Can you share your whole code? Where is this xyz__Share share table referenced in your code? Jul 26, 2019 at 7:28
  • Updated my code, it was just example. Thanks for feedback @ProlayChaudhury Jul 26, 2019 at 7:44
  • By changing code from public with sharing class EVT_Client_Assessment_TriggerHandler to public class EVT_Client_Assessment_TriggerHandler works correctly Aug 1, 2019 at 11:53
  • Replace public with sharing class EVT_Client_Assessment_TriggerHandler with public Without Sharing class EVT_Client_Assessment_TriggerHandler Aug 13, 2019 at 10:09

0

You must log in to answer this question.

Browse other questions tagged .