• siva kurma
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
APEX CLASS
public class AccountOwnerCheck {
    public static void OwnerCheck(list<Account> VarAccList){
        for(Account VarAccounts:VarAccList){
            if(VarAccounts.OwnerId != UserInfo.getUserId()) {
                VarAccounts.addError('You dont have the permission to delete the record, Only Owner can delete');
            }          
        }
    }
}

APEX TRIGGER
trigger AccountDeleteTrigger on Account (before Delete) {
    
    if(Trigger.iSBefore == true && Trigger.isDelete == True){
        AccountOwnerCheck.OwnerCheck(Trigger.Old);
    }
}


TEST CLASS
@isTest
class AccountOwnerCheckTest {
   static testMethod void testMethod1() 
    {
            Account newAcc = new Account() ;
            newAcc.Name = 'Cole';
            insert newAcc;

            try
            {
                Delete     newAcc;
            }
            catch(Exception ee)
            {}
    }
}
APEX CLASS
public class AccountOwnerCheck {
    public static void OwnerCheck(list<Account> VarAccList){
        for(Account VarAccounts:VarAccList){
            if(VarAccounts.OwnerId != UserInfo.getUserId()) {
                VarAccounts.addError('You dont have the permission to delete the record, Only Owner can delete');
            }          
        }
    }
}

APEX TRIGGER
trigger AccountDeleteTrigger on Account (before Delete) {
    
    if(Trigger.iSBefore == true && Trigger.isDelete == True){
        AccountOwnerCheck.OwnerCheck(Trigger.Old);
    }
}


TEST CLASS
@isTest
class AccountOwnerCheckTest {
   static testMethod void testMethod1() 
    {
            Account newAcc = new Account() ;
            newAcc.Name = 'Cole';
            insert newAcc;

            try
            {
                Delete     newAcc;
            }
            catch(Exception ee)
            {}
    }
}