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
Zhen Zhang 22Zhen Zhang 22 

System.DmlException: Delete failed. First exception on row 0 with id 00t0U00000RD77SQAT; first error: INVALID_CROSS_REFERENCE_KEY, id does not exist: []

I just want to delete the opportunityshare record as below code. but when I delete it , it give me the error message as the title shows.(System.DmlException: Delete failed. First exception on row 0 with id 00t0U00000RD77SQAT; first error: INVALID_CROSS_REFERENCE_KEY, id does not exist: []). and I checked the result from database , I found the record has been deleted but new record inserted into the database(new record is the same to the old one except the record id).
Anyone who has ever met this kind error before? I would appreciate if anyone can help me . Really thanks a lot.


List<OpportunityShare> oppShareListDel = [SELECT id from OpportunityShare where OpportunityId in: oppIdListForShareDel and Rowcause = 'Manual' and userorgroupid in: oppUserOrGroupIdListAll];
 try{
          delete oppShareListDel;
 }catch(Exception excep){
          System.debug('error aaa:::  '+excep);
  }                   
Rahul.MishraRahul.Mishra
Hi,
Could you please post your code here, unable to find cause exactly with given information. Mostly this error gets triggered when we assign wrong Id to record, you could also do following checkes:

1. Initalize your list:

List<OpportunityShare> oppShareListDel = new List<OpportunityShare> ();
oppShareListDel  =[SELECT id from OpportunityShare where OpportunityId in: oppIdListForShareDel and Rowcause = 'Manual' and userorgroupid in: oppUserOrGroupIdListAll];

2. Check the values in oppIdListForShareDel , does it return correct Opportunity ids or not.
3. Check te values in oppUserOrGroupIdListAll, does it return correct user or group ids or not.
4. Check the size of list before deleting, 
if(!oppShareListDel.isEmpty())
 delete oppShareListDel ;
Zhen Zhang 22Zhen Zhang 22
Hi Rahul,
   I checked the oppShareListDel and it is the correct list and is not empty as below shows . Actually it has already been deleted but generated the new one ... could you please help to analyze the issue?
Is there any other reason?  Thanks a lot for your reply...


(OpportunityShare:{Id=00t0U00000RD77SQAT}, OpportunityShare:{Id=00t0U00000RD77XQAT})
RAJASEKARAN BhuvaneshwariRAJASEKARAN Bhuvaneshwari
Hi,
Im also facing the same issue. Whether you are able to fix it up?