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
sfdeveloper12sfdeveloper12 

Getting an error while deleting a record.

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
Best Answer chosen by sfdeveloper12
Luke WoodsLuke Woods
Hello Utkarsha,

I believe the issue that you are having here is that you do not have permissions to DELETE records of this Object type. Your account has been restriced to I presume, read/write, but this does not mean that you are allowed to delete. You would need to get an administrator to enable your delete priveledges on this object type before you can use your trigger.

I hope this helps, Take care,

Luke

All Answers

Luke WoodsLuke Woods
Hello Utkarsha,

I believe the issue that you are having here is that you do not have permissions to DELETE records of this Object type. Your account has been restriced to I presume, read/write, but this does not mean that you are allowed to delete. You would need to get an administrator to enable your delete priveledges on this object type before you can use your trigger.

I hope this helps, Take care,

Luke
This was selected as the best answer
Maharajan CMaharajan C
Hi Utkarsha,

Refer the below links:

https://salesforce.stackexchange.com/questions/9076/revoking-apex-managed-sharing-permission

https://developer.salesforce.com/forums/?id=906F000000096RzIAI

Can you please Let me know if it works or not and also If you face any problems!!!

If it works don't forget to mark this as a best answer!!!

Thanks,
​Raj
sfdeveloper12sfdeveloper12
Thank you both. Both the solutions are correct. 
thank you very much for resolving my issue.
Felicity AylinFelicity Aylin
Clearly, you can purchase a wallet affix at whatever point you want to from any place you need as there is a tremendous assortment out there accessible in many stores, however to go for the most ideal choice by remembering, the right size is the genuine article. You might never want to spend a decent sum on one and think twice about it later as the size is not exactly right on your outfit. https://sanityjewelry.hpage.com/
hs dsd 10hs dsd 10
Jewelers mutual is the pleasant rings insurer recommended via way of the maximum well-known corporations inside the earrings industry – government like american gem society and jewelers (https://www.jewelrynest.com/designer-diamond-necklaces/stylish-pearl-gold-necklace.html).
john smith 979john smith 979
Jewelers Mutual is a really good jewelry insurance company. Big names in the jewelry world, like the American Gem Society and Jewelers, suggest it as the top choice for getting your jewelry insured.