I have a OWD Case is Private and its child Object (Payment also Private). I have Lookup relationship with Case and Payment object..

When Case is created its owner will changed as per the Case Assignment Rules.

  1. The moment Case owner changes, I need to give access to the Child object what Case object has. --> This I was able to achieve.
  2. And Need to give Read only access to the original requestor on both Case & Payment object.

I am getting the below error..

field integrity exception: RowCause (Specified value is reserved and cannot be used)
field integrity exception: unknown (Specified value is reserved and cannot be used)
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: RowCause (Specified value is reserved and cannot be used): [RowCause]
"common.apex.runtime.impl.DmlExecutionException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: RowCause (Specified value is reserved and cannot be used): [RowCause]"|0x6ca73acc

Code below for reference..

public static void CaseOwner(Map<Id, Case> newCasesMap, Map<Id, Case> oldCasesMap){       
    List<Payment__Share> pshareList = new List<Payment__Share>(); 
    if(oldCasesMap != null){
        // Assigned Owner to Child object looking at Owner of Case object ----
        List<Case> caseList = [Select Id,OwnerId, (select Id, OwnerId from Payment__r), (select Id,OwnerId  from Payment_2__r) 
                                     FROM Case 
                                     WHERE Id IN :newCasesMap.keySet()];    

       List<CaseShare> caseShares = new list<CaseShare>();
        for(Id Ids : oldCasesMap.keyset()){
            Case oldcase = oldCasesMap.get(Ids);
            Case newCase = newCasesMap.get(Ids);

            if(oldcase.OwnerId != newCase.OwnerId){
                CaseShare cShare = new CaseShare();
                cShare.caseId = Ids;
                cShare.CaseAccessLevel = 'Read';
                cShare.RowCause = 'Manual';
                if(oldcase.CreatedById != null)
                    cShare.UserOrGroupId = oldcase.CreatedById;
                    cShare.UserOrGroupId = newCase.CreatedById;

                if(caseList.size() > 0){
                    List<Payment__c> siList = caseList[0].Payment__r;

                    if(siList.size() > 0){

                        Payment__Share pShare = new Payment__Share();
                        pShare.ParentId = siList[0].Id;
                        pShare.RowCause = 'Manual';
                        pShare.AccessLevel = 'Read';
                        if(siList[0].OwnerId != newCase.OwnerId)
                            pShare.UserOrGroupId = newCase.OwnerId;
                            pShare.UserOrGroupId = newCase.OwnerId;                            
        insert caseShares;
        insert pshareList;       
  • I don't think you need to specify RowCause = 'Manual'. IIRC that's the default value. Try removing the lines where you set that field. – Adrian Larson Jan 16 '18 at 17:57
  • Even if I dont set any value, just dont populate and left to make assignment... still seeing the same issue... – Kanika Jan 16 '18 at 18:02
  • Did you remove all the lines of code where you set it? There is more than one such line in the code you included above. – Adrian Larson Jan 16 '18 at 18:07
  • I just removed pShare.RowCause = 'Manual'; because error coming for the Child Object - Payment. Shall I removed from all places ? – Kanika Jan 16 '18 at 18:09
  • 1
    Do not add comments begging for help. They will be removed. – Adrian Larson Jan 16 '18 at 18:49

I could think of adding the same user in the Case Team so that previous owner will have access to the same case.

So, define a Case team role 'Team Role Name' and define access as 'Read Only' and assign the user to the case team as follows when ownership is getting changed:

public void addCaseTeamMembersToCase(List<Case> lstNewCases, Map<Id,Case> mapOldCases)
    Map<String, String> mapCaseOwnerId = new Map<String,String>();

    for(Case objCase:lstNewCases)
        String oldOwnerId = mapOldCases.get(objCase.Id).ownerId;
        String newOwnerid = objCase.ownerId;

            && oldOwnerId !=null && oldOwnerId.subString(0,3) == '005' 
            mapCaseOwnerId.put(objCase.Id, oldOwnerId);                         
    List<CaseTeamMember> lstCaseTeamMember = [SELECT ParentId, MemberId FROM CaseTeamMember
                                            WHERE ParentId =: mapCaseOwnerId.keySet()
                                            AND MemberId =: mapCaseOwnerId.values()];

    if(lstCaseTeamMember.size() == 0)
        for(String strCaseId:mapCaseOwnerId.keySet())
               new CaseTeamMember(             
                      ParentId = strCaseId,                           
                      MemberId = mapCaseOwnerId.get(strCaseId)

    if (!mapMembersToAdd.isEmpty())

        objCaseTeamRole = [SELECT Id
                                  FROM CaseTeamRole 
                                  WHERE Name = 'Team Role Name' LIMIT 1];
        for (CaseTeamMember objCaseTeamMember : mapMembersToAdd.values())
                objCaseTeamMember.TeamRoleId = objCaseTeamRole.Id;
        if (!mapMembersToAdd.isEmpty())
            insert mapMembersToAdd.values();
  • In my org, I have almost 40,000 users and cant add everyone in Case Team, dont know how many users will create ? If comment the logic of updating Child object owner as Case owner, now error has gone, but still Payment_Share is not creating... What is mapMembersToAdd in your code ? – Kanika Jan 16 '18 at 19:13
  • mapMembersToAdd is for caseteam members to add. Secondly this is efficient way to manage access. You can explore Apex Managed Sharing with a custom sharing reason, refer developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… – Santanu Boral Jan 16 '18 at 19:33
  • is that my answer solved your purpose? – Santanu Boral Jan 18 '18 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.