You need to sign in to do that
Don't have an account?
Vidya H 4
plese help me to write test class for this trigger
trigger OppValidation on Opportunity (before insert,before update) {
Id profileId= userinfo.getProfileId();
String profileName=[Select Id,Name from Profile where Id=:profileId].Name;
if(Trigger.isupdate){
for(Opportunity opp:Trigger.new){
opportunity oldoppy= Trigger.oldmap.get(opp.id);
if(opp.Active__c ==false && oldoppy.Active__c==True && opp.stagename!='Closed Won' && profileName!='System Administrator'){
opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
}
}
}
if(Trigger.isinsert){
for(Opportunity opp:Trigger.new){
if(opp.Active__c ==false && opp.stagename!='Closed Won' && profileName!='System Administrator'){
opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
}
}
}
}
Id profileId= userinfo.getProfileId();
String profileName=[Select Id,Name from Profile where Id=:profileId].Name;
if(Trigger.isupdate){
for(Opportunity opp:Trigger.new){
opportunity oldoppy= Trigger.oldmap.get(opp.id);
if(opp.Active__c ==false && oldoppy.Active__c==True && opp.stagename!='Closed Won' && profileName!='System Administrator'){
opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
}
}
}
if(Trigger.isinsert){
for(Opportunity opp:Trigger.new){
if(opp.Active__c ==false && opp.stagename!='Closed Won' && profileName!='System Administrator'){
opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
}
}
}
}
Can you try the below test class for the trigger.
Replace the profile name in the query to which ever profile who want to test it withb except system admin profile.
If this solution helps, please mark it as best answer.
Thanks,
All Answers
Can you try the below test class for the trigger.
Replace the profile name in the query to which ever profile who want to test it withb except system admin profile.
If this solution helps, please mark it as best answer.
Thanks,
after run test getting error
System.QueryException: List has no rows for assignment to SObject