You need to sign in to do that
Don't have an account?
Eklavyam
trigger handler class help !
Hello,
My trigger :
trigger stopTaskDelete on Task (before delete) {
Id profileid = Userinfo.getProfileId();
profile profilename = [select Name from Profile where id=:profileid];
for(Task T1:Trigger.old){
if(profilename.Name != 'System Administrator'){
T1.adderror('You can not delete task');
}
}
}
How can I make this trigger work via Handler class? and how do I write test class for this?
My trigger :
trigger stopTaskDelete on Task (before delete) {
Id profileid = Userinfo.getProfileId();
profile profilename = [select Name from Profile where id=:profileid];
for(Task T1:Trigger.old){
if(profilename.Name != 'System Administrator'){
T1.adderror('You can not delete task');
}
}
}
How can I make this trigger work via Handler class? and how do I write test class for this?
Your Trigger I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Hi Eklavyam,
Use runAs() to run your code in different user context. please refer below link find out more about runAs().
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_runas.htm
Check the below code to get an idea of how we can write a test class for your sample code, I have tested and code is working fine.
Trigger
Trigger Handler
Test Class
Hope It will help you :)
You can create a class Trigger Handler and call its method i.e. deleteTask from Trigger Body
I have found the same issue, here is the link. Please follow the below link that may be helpful for you:
https://developer.salesforce.com/forums?id=9062I000000IIYjQAOs
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi