You need to sign in to do that
Don't have an account?
IFTHIKAR 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');
}
}
}
}
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');
}
}
}
}
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
Best Regards,
Dushyant Srivastava
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.
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.