You need to sign in to do that
Don't have an account?
siva kurma
Testclass help for before delete scenario? Test class is giving me 75% coverage but i want 100%
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)
{}
}
}
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)
{}
}
}
Try this test class:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
All Answers
Try this test class:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Also I wrote a trigger to update contact fields based on Account fileds. I always thought after triggers are needed if you hvae to work on 1 record bassed on another record. Starnegly i could finish the job with before trigger. How ?