You need to sign in to do that
Don't have an account?
DEEPALA SIVA
execution of AfterUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00r3I00000favMPQAY; first error: INVALID_CROSS_REFERENCE_KEY, id does not exist: [
while deleting the Accountshare through Trigger, getting the following error, can anyone please suggest me what is wrong here,
public static void accountShareUpdateBoBDelete(list<GA_AOR__c> OldaorLst , Map<Id, GA_AOR__c> OldmapAOR){
List<Id> listConId = new List<Id>();
List<Id> listAccId = new List<Id>();
for(GA_AOR__c aor : OldaorLst){
GA_AOR__c olAOR = OldmapAOR.get(aor.Id);
if( (aor.GA_Service_End_Date__c != olAOR.GA_Service_End_Date__c && aor.GA_Service_End_Date__c <= system.today()) ||
(aor.GA_Service_Start_Date__c != olAOR.GA_Service_Start_Date__c && aor.GA_Service_Start_Date__c >=system.today()))
{
listConId.add(olAOR.GA_Contact_Id__c);
listAccId.add(olAOR.GA_Account_Id__c);
}
List<User> userList = [SELECT ID, ContactId
FROM User WHERE ContactId =: listConId];
List<Accountshare> listAccshare = [SELECT Id, AccountId,UserOrGroupId
FROM AccountShare WHERE AccountId=: listAccId AND UserOrGroupId=:userList and Rowcause='Manual'];
system.debug('listAccshare--->'+listAccshare);
If(listAccshare.size() > 0)
{
//delete listAccshare;
Database.delete(listAccshare);
}
}
calling this method in AfterUpdate
public static void accountShareUpdateBoBDelete(list<GA_AOR__c> OldaorLst , Map<Id, GA_AOR__c> OldmapAOR){
List<Id> listConId = new List<Id>();
List<Id> listAccId = new List<Id>();
for(GA_AOR__c aor : OldaorLst){
GA_AOR__c olAOR = OldmapAOR.get(aor.Id);
if( (aor.GA_Service_End_Date__c != olAOR.GA_Service_End_Date__c && aor.GA_Service_End_Date__c <= system.today()) ||
(aor.GA_Service_Start_Date__c != olAOR.GA_Service_Start_Date__c && aor.GA_Service_Start_Date__c >=system.today()))
{
listConId.add(olAOR.GA_Contact_Id__c);
listAccId.add(olAOR.GA_Account_Id__c);
}
List<User> userList = [SELECT ID, ContactId
FROM User WHERE ContactId =: listConId];
List<Accountshare> listAccshare = [SELECT Id, AccountId,UserOrGroupId
FROM AccountShare WHERE AccountId=: listAccId AND UserOrGroupId=:userList and Rowcause='Manual'];
system.debug('listAccshare--->'+listAccshare);
If(listAccshare.size() > 0)
{
//delete listAccshare;
Database.delete(listAccshare);
}
}
calling this method in AfterUpdate
Anudeep (Salesforce Developers)
All of the AccountShares are automatically created by sharing rules, so they cannot be deleted. If they want to remove them, you need to change the sharing rule