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
IFTHIKAR AHMED 7IFTHIKAR AHMED 7 

Trigger : There's a problem saving this record. You might not have permission to edit it, or it might have been deleted or archived. Contact your administrator for help.

Hi getting error when trying to delete a recourd wher record owner != logged in user below is my code 

trigger MobDiscount on Mobile__c (before insert,before update,before delete) {
Trigger :     
    if(Trigger.isinsert == true)
    {
        DiscountForMobiles.DiscountNewCoustomer(Trigger.new);
    }
    
    if(Trigger.isupdate == true)
    {
        DiscountForMobiles.DiscountOldCoustomer(Trigger.new);
    }
    
    if(Trigger.isdelete == true && Trigger.isbefore == true)
    {
        DiscountForMobiles.OwnwerAloneCanDelete(Trigger.old);
    }
    
}

Apex Class :

public class DiscountForMobiles {
    
    Public Static Void DiscountNewCoustomer(List<Mobile__c> CoustomerList)
    {
        for(Mobile__c SingleCoustomer : CoustomerList ){
            
            If(SingleCoustomer.Brand__c == 'Samsung')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c * 10/100;
               SingleCoustomer.Discount_Status__c = '10 % Discount';
            }
            
            if(SingleCoustomer.Brand__c == 'Apple')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c - SingleCoustomer.Price__c * 5/100;
               SingleCoustomer.Discount_Status__c = '5 % Discount';
            }
            
        }
        
    }

    Public Static Void DiscountOldCoustomer(List<Mobile__c> CoustomerList)
    {
        for(Mobile__c SingleCoustomer : CoustomerList ){
            
            If(SingleCoustomer.Brand__c == 'Samsung')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c - SingleCoustomer.Price__c * 10/100;
               SingleCoustomer.Discount_Status__c = '5 % Discount';
            }
            
            If(SingleCoustomer.Brand__c == 'Apple')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c * 5/100;
               SingleCoustomer.Discount_Status__c = 'NO Discount';
            }
            
        }
        
    }
    Public Static Void OwnwerAloneCanDelete(List<Mobile__c> CoustomerList)
    {
        
        for(Mobile__c Costomer : CoustomerList)
        {
            If(Costomer.OwnerId != Userinfo.getUserId())
            {
                Costomer.adderror('only owner can delete');
            }
        }
         
    }
      
}
IFTHIKAR AHMED 7IFTHIKAR AHMED 7
everything is fine with profile level settings
Dushyant srivastava 8Dushyant srivastava 8
Hi IFTHIKAR,

The Class looks fine to me all you need to check if the Object and the fields used have the edit permission or if you want you can test the same with withousharing for class
 
public without sharing class YOUR_CLASS
{
    public static void YOUR_METHOD()
   {
      .........CUSTOM CODE........
   }
}

Best Regards,
Dushyant Srivastava
Kalyan RanjanKalyan Ranjan
I'm also facing the same problem. This happens because of the delete event of the trigger. 
Juan Pablo Rodriguez 3Juan Pablo Rodriguez 3

Hi @IFTHIKAR AHMED 7!,

I faced the same error on before delete context variable apex trigger. I solved the issue applying ModifyAll permission level over object to delete records.

 

I hope this works for you.

Arun Kumar 1141Arun Kumar 1141
Hello Ifthikar,

If you have checked the permissions for the profile then you must also confirm that this user is not having any record level restrictions. This seems that you should check the sharing settings of the custom object records you are trying your trigger on, ensure that sharing settings are allowing the user to read as well as delete(edit) the record.

Hope this helps you.
Thanks.