function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Soundar Rajan PonpandiSoundar Rajan Ponpandi 

FIELD_INTEGRITY_EXCEPTION, Parent ID: id value of incorrect type: a0g0C000001NvFxQAK: [ParentId]

Hi,

I am trying to share a custom quote record to user's. But i am facing following error.
This Record is having "Control By Parent" access.
Even i tried with opportunity as a parentId.
DEBUG|Exception -System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Parent ID: id value of incorrect type: a0g0C000001NvFxQAK: [ParentId]

Can you please tell me where i did  a mistake and how can i achieve it in a success way.
 
public class GD_CreateQuoteTeam { 
    @AuraEnabled
    public static void saveQuoteTeam(List<GD_Quote_Team__c> teamList, string quoteId){
        try{
        list<GD_Quote_Team__c> qtTeamList = new list<GD_Quote_Team__c>();
        list<GD_Quote_Team__Share> readShareList = new list<GD_Quote_Team__Share>();
        list<GD_Quote_Team__Share> editShareList = new list<GD_Quote_Team__Share>();
        for(GD_Quote_Team__c team : teamList){
            team.GD_Quotes__c = quoteId;
            qtTeamList.add(team);
        }
        Insert qtTeamList;
        /*Share Record - Read Only*/
        for(gd_quote_Team__c qTeam : [select id,name,GD_user__c from gd_quote_Team__c where GD_Quotes__c =: quoteId and GD_Quote_access__c = 'Read Only']){
            GD_Quote_Team__Share shareRecord = new GD_Quote_Team__Share();
                shareRecord.AccessLevel = 'Read';
                shareRecord.UserOrGroupId = qTeam.GD_user__c;
                shareRecord.ParentId = quoteId;
                readShareList.add(shareRecord);
        }
        if(readShareList.size()>0){insert readShareList;}        
        /*Share Record - Read/Write*/
        for(gd_quote_Team__c qTeam : [select id,name,GD_user__c from gd_quote_Team__c where GD_Quotes__c =: quoteId and GD_Quote_access__c = 'Read/write']){
            GD_Quote_Team__Share shareRecord = new GD_Quote_Team__Share();
                shareRecord.AccessLevel = 'edit';
                shareRecord.UserOrGroupId = qTeam.GD_user__c;
                shareRecord.ParentId = quoteId;
                editShareList.add(shareRecord);
        }
        if(editShareList.size()>0){insert editShareList;} 
            }catch(Exception e){system.debug('Exception -' + e);}
        
    }
    
}

Many Thanks in Advance.
Soundar Rajan P.
Best Answer chosen by Soundar Rajan Ponpandi
ANUTEJANUTEJ (Salesforce Developers) 
Hi Soundar,

As mentioned in the error can you try checking if the id that is mentioned is correct??

Regards,
Anutej

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Soundar,

As mentioned in the error can you try checking if the id that is mentioned is correct??

Regards,
Anutej
This was selected as the best answer
Soundar Rajan PonpandiSoundar Rajan Ponpandi
Hi Anutej,

as i mentioned in the coding line no 18 & 27 " shareRecord.ParentId = quoteId;" i have provided quoteId as parent. I thing quote is the parent of this Quote_Team__c object.

Which id i need to pass here ? (Quote Id only ?)

Regards,
Soundar.
ANUTEJANUTEJ (Salesforce Developers) 
Can you try checking if the function is working properly if the value is hardcoded?
Soundar Rajan PonpandiSoundar Rajan Ponpandi
HI ANUTEJ,

You are correct ! By mistake i have provided a quote id instead of opportunity ID. Because if any record under the Opportunity that's directly don't have a permission to share. Those records basically controlled by parent, Here parent is opportunity. So Obviously we should share the opportunity records as well.

I have changed my code and  trying to share opportunity record but i am facing following Error (In sufficient Access)
 
Error:

12:02:24:180 USER_DEBUG [37]|DEBUG|Exception -System.DmlException: Insert failed. First exception on row 7; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

Modified Code
 
public class GD_CreateQuoteTeam { 
    @AuraEnabled
    public static void saveQuoteTeam(List<GD_Quote_Team__c> teamList, string quoteId){
        try{
            system.debug('Enter Into the Apex ******' + teamList);
            list<GD_Quote_Team__c> qtTeamList = new list<GD_Quote_Team__c>();
            list<opportunityShare> readShareList = new list<opportunityShare>();
            list<opportunityShare> editShareList = new list<opportunityShare>();    
            
            GD_Quote__c qt = [select id,GD_Opportunity__c from GD_Quote__c where id =: quoteId];
            id oppId = qt.GD_Opportunity__c;
            for(GD_Quote_Team__c team : teamList){
                team.GD_Quotes__c = quoteId;
                qtTeamList.add(team);
            }
            Insert qtTeamList;
            
            for(gd_quote_Team__c qTeam : [select id,name,GD_user__c from gd_quote_Team__c where GD_Quotes__c =: quoteId and GD_Quote_access__c = 'Read Only']){
                opportunityShare shareRecord = new opportunityShare();
                shareRecord.OpportunityAccessLevel = 'Read';
                shareRecord.UserOrGroupId = qTeam.GD_user__c;
                shareRecord.OpportunityId = oppId;
                readShareList.add(shareRecord);
            }
            if(readShareList.size()>0){insert readShareList;system.debug('Read Access Provided');}        
           
            for(gd_quote_Team__c qTeam : [select id,name,GD_user__c from gd_quote_Team__c where GD_Quotes__c =: quoteId and GD_Quote_access__c = 'Read/write']){
                opportunityShare shareRecord = new opportunityShare();
                shareRecord.OpportunityAccessLevel = 'edit';
                shareRecord.UserOrGroupId = qTeam.GD_user__c;
                shareRecord.OpportunityId = quoteId;
                editShareList.add(shareRecord);
            }
            if(editShareList.size()>0){insert editShareList;system.debug('Edit Access Provided');} 
        }catch(Exception e){system.debug('Exception -' + e);}
        
    }
    
}

Many Thanks for your support.
Soundar Rajan P. 
ANUTEJANUTEJ (Salesforce Developers) 
Glad to know that we were able to identify the id error. :)
Soundar Rajan PonpandiSoundar Rajan Ponpandi
Hi ANUTEJ,

I have fixed this issue.

in line No 31 also i did mistake (now provided a Opportunity Id instead of quote Id).

Thanks for your valuable support. I will mark your reply as best answer.

Regards,
Soundar.