• Luke Woods
  • NEWBIE
  • 25 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello,

I am doing task where i want to delete share record but its giving me an error as shown below. 
"Insufficient Privileges
You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. For more information, see Insufficient Privileges Errors."

Account {"Party_Sea_ID__c":8375,"Customer_Number__c":"C3092","Name":"VILLAGE JEWELRY OUTLET OF KANNAPOLIS, INC.","DBA_Name__c":"VILLAGE JEWELRY OUTLET OF KANNAPOLIS, INC.","Customer_Group_Id__c":"a0028000015lr7TAAQ","OwnerId":"00528000003iGolAAE","owner1__c":"00528000003iL8FAAU","Terms_Id__c":"a042800000oV26ZAAS","Default_Currency__c":"US DOLLARS","No_of_Doors__c":0,"NumberOfEmployees":0,"Store_Size__c":0,"Status__c":0,"Sales_Code__c":"NONE","RecordTypeId":"01228000000QbiM","Asset_Credit_Limit__c":0,"Memo_Credit_Limit__c":0,"Outstanding_A_R_Balance__c":0,"Outstanding_Memo_Balance__c":0} Delete_Share: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00r28000020WN31AAG; first error: DELETE_FAILED, cannot delete owner or rule share rows, id=00r28000020WN31: [] Trigger.Delete_Share: line 29, column 1

My trigger is as followed.

trigger Delete_Share on Account (before update) {


set<Id> AccountIDs = new Set<Id>();
for(Account a: trigger.new){
AccountIDs.add(a.id);
}
List<AccountShare> jobShares = new List<AccountShare>();

map<String,AccountShare>accountShareMap = new Map<String,AccountShare>();

for(AccountShare accShare : [select AccountId,UserOrGroupId from AccountShare where AccountId in :AccountIds])
{
 accountShareMap.put(String.valueOf(accShare.UserOrGroupId),accShare);

}

for(Account a : trigger.new){
Account oldAccount = Trigger.OldMap.get(a.id);
if (a.owner1__c != null && a.owner1__c !=oldAccount.owner1__c) {
 
   AccountShare accountRecord = accountShareMap.get(string.valueOf(oldAccount.owner1__c)); 
    if (accountRecord  != null)
    jobShares.add(accountRecord);
  }
 }

if(jobShares.isEmpty() == false){
 delete jobShares;
 }
}

29th line is this :  delete jobShares;

Please help me. i dont know why is this happening.

Thanks & Best Regards,
Utkarsha
Hello,

I am doing task where i want to delete share record but its giving me an error as shown below. 
"Insufficient Privileges
You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. For more information, see Insufficient Privileges Errors."

Account {"Party_Sea_ID__c":8375,"Customer_Number__c":"C3092","Name":"VILLAGE JEWELRY OUTLET OF KANNAPOLIS, INC.","DBA_Name__c":"VILLAGE JEWELRY OUTLET OF KANNAPOLIS, INC.","Customer_Group_Id__c":"a0028000015lr7TAAQ","OwnerId":"00528000003iGolAAE","owner1__c":"00528000003iL8FAAU","Terms_Id__c":"a042800000oV26ZAAS","Default_Currency__c":"US DOLLARS","No_of_Doors__c":0,"NumberOfEmployees":0,"Store_Size__c":0,"Status__c":0,"Sales_Code__c":"NONE","RecordTypeId":"01228000000QbiM","Asset_Credit_Limit__c":0,"Memo_Credit_Limit__c":0,"Outstanding_A_R_Balance__c":0,"Outstanding_Memo_Balance__c":0} Delete_Share: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00r28000020WN31AAG; first error: DELETE_FAILED, cannot delete owner or rule share rows, id=00r28000020WN31: [] Trigger.Delete_Share: line 29, column 1

My trigger is as followed.

trigger Delete_Share on Account (before update) {


set<Id> AccountIDs = new Set<Id>();
for(Account a: trigger.new){
AccountIDs.add(a.id);
}
List<AccountShare> jobShares = new List<AccountShare>();

map<String,AccountShare>accountShareMap = new Map<String,AccountShare>();

for(AccountShare accShare : [select AccountId,UserOrGroupId from AccountShare where AccountId in :AccountIds])
{
 accountShareMap.put(String.valueOf(accShare.UserOrGroupId),accShare);

}

for(Account a : trigger.new){
Account oldAccount = Trigger.OldMap.get(a.id);
if (a.owner1__c != null && a.owner1__c !=oldAccount.owner1__c) {
 
   AccountShare accountRecord = accountShareMap.get(string.valueOf(oldAccount.owner1__c)); 
    if (accountRecord  != null)
    jobShares.add(accountRecord);
  }
 }

if(jobShares.isEmpty() == false){
 delete jobShares;
 }
}

29th line is this :  delete jobShares;

Please help me. i dont know why is this happening.

Thanks & Best Regards,
Utkarsha