You need to sign in to do that
Don't have an account?
NHameed
Need help writing Test Class for this Trigger Please
Trigger will prevent addition or deletion of Opportunity Team Member if "Opportunity_Team_Locked__c" on Opportunity =True.
Trigger:
"Trigger OpptyTeamLock on OpportunityTeamMember (Before Insert,Before Delete){
set<Id> oppIdSet = new set<id>();
If(Trigger.IsBefore){
If(Trigger.IsInsert){
for(OpportunityTeamMember otm : trigger.new){
oppIdSet.add(otm.OpportunityId);
}
}
If(Trigger.IsDelete){
for(OpportunityTeamMember otm : trigger.old){
oppIdSet.add(otm.OpportunityId);
}
}
}
list<Opportunity>lstOpp = [select Id,Name,Opportunity_Team_Locked__c from opportunity where Id In :oppIdSet and Opportunity_Team_Locked__c = true];
If(Trigger.IsBefore){
If(Trigger.IsInsert){
for(OpportunityTeamMember otm : trigger.new){
if(lstOpp.Size()>0){
otm.AddError('Error Message');
}
}
}
If(Trigger.IsDelete){
for(OpportunityTeamMember otm : trigger.old){
if(lstOpp.Size()>0){
otm.AddError('Opportunity Team is locked. Contact Commission Team');
}
}
}
}
}"
This is my test class so far. Not only it's failing but it also needs the Before Delete part added.
"@isTest
Public class OpptyTeamLock_Test{
public static testmethod void OpptyTeamTest()
{
Opportunity Opp = new Opportunity (Name ='TestOTMOpportunity',StageName ='Prospecting', Type = 'New Customer',License_Type__c= 'Direct');
insert Opp;
List <OpportunityTeamMember> OTM = new List <OpportunityTeamMember> {
new OpportunityTeamMember (TeamMemberRole = 'TSE Owner',OpportunityAccessLevel='Read Only')
};
insert OTM;
}
}"
Thanks in advance.
Trigger:
"Trigger OpptyTeamLock on OpportunityTeamMember (Before Insert,Before Delete){
set<Id> oppIdSet = new set<id>();
If(Trigger.IsBefore){
If(Trigger.IsInsert){
for(OpportunityTeamMember otm : trigger.new){
oppIdSet.add(otm.OpportunityId);
}
}
If(Trigger.IsDelete){
for(OpportunityTeamMember otm : trigger.old){
oppIdSet.add(otm.OpportunityId);
}
}
}
list<Opportunity>lstOpp = [select Id,Name,Opportunity_Team_Locked__c from opportunity where Id In :oppIdSet and Opportunity_Team_Locked__c = true];
If(Trigger.IsBefore){
If(Trigger.IsInsert){
for(OpportunityTeamMember otm : trigger.new){
if(lstOpp.Size()>0){
otm.AddError('Error Message');
}
}
}
If(Trigger.IsDelete){
for(OpportunityTeamMember otm : trigger.old){
if(lstOpp.Size()>0){
otm.AddError('Opportunity Team is locked. Contact Commission Team');
}
}
}
}
}"
This is my test class so far. Not only it's failing but it also needs the Before Delete part added.
"@isTest
Public class OpptyTeamLock_Test{
public static testmethod void OpptyTeamTest()
{
Opportunity Opp = new Opportunity (Name ='TestOTMOpportunity',StageName ='Prospecting', Type = 'New Customer',License_Type__c= 'Direct');
insert Opp;
List <OpportunityTeamMember> OTM = new List <OpportunityTeamMember> {
new OpportunityTeamMember (TeamMemberRole = 'TSE Owner',OpportunityAccessLevel='Read Only')
};
insert OTM;
}
}"
Thanks in advance.
The below test class covered around 94% of the code. If required we can make to 100% as well by inserting another team member in second method.
If this solution helps,Please mark it as best answer.
Thanks,
All Answers
The below test class covered around 94% of the code. If required we can make to 100% as well by inserting another team member in second method.
If this solution helps,Please mark it as best answer.
Thanks,
Thanks for your prompt help but both tests are failing. Can you please help me refine this a bit more. Thanks
Can you check the error and confirm where it is failing so can modify accordingly.
Thanks,
Thanks again.
Are you sure, Do you have profile name Jason Todd in your org.
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
I hope you dont have profile with name Jason Todd. You can use the standard user profile only as it is given by salesforce.
Thanks,