You need to sign in to do that
Don't have an account?

Can someone help build a test class?
Hi, I have an apex trigger that I pieced together and tested out and it works. But now I need a test class in order to move it to production. Any help is appreciated.
Here is my trigger:
trigger InsertOppTeam on OpportunityTeamMember (after insert, after update) {
//Using set to be able to work with setOpp and setOTM SETS
set<Id> setOpp = new set<Id>();
set<Id> setOTM = new set<Id>();
for (OpportunityTeamMember oppTeam : trigger.new) {
setOpp.add(oppTeam.OpportunityId);
setOTM.add(oppTeam.id);
}
//Loop through opportunity team members and grab Users who have these roles 'OL Assignment' or 'Sage Buddy' or 'Mentor'.
list<OpportunityTeamMember> listOTM = new list<OpportunityTeamMember>
([SELECT Id, UserId, OpportunityId, TeamMemberRole, User.Name FROM OpportunityTeamMember WHERE Id in :setOTM AND (TeamMemberRole = 'OL Assignment' OR
TeamMemberRole = 'Sage Buddy' OR TeamMemberRole = 'Mentor') ]);
// Create a map that grabs the Opportunity Id being worked with
Map<Id,Opportunity> mapOpps = new map<Id, Opportunity>([SELECT Id FROM Opportunity Where Id = :setOpp ]) ;
Opportunity tempOpp;
//Load the ID's
for(OpportunityTeamMember otm : listOTM ){
tempOpp = mapOpps.get(otm.OpportunityId);
if(otm.TeamMemberRole == 'OL Assignment') {
tempOpp.OL_Assignment1__c = otm.User.Name;
}
else if(otm.TeamMemberRole == 'Mentor') {
tempOpp.Mentor__c = otm.User.Name;
}
else if(otm.TeamMemberRole == 'Sage Buddy') {
tempOpp.Sage_Buddy__c = otm.User.Name;
}
}
// Load values
update mapOpps.values();
}
Thank you!
Here is my trigger:
trigger InsertOppTeam on OpportunityTeamMember (after insert, after update) {
//Using set to be able to work with setOpp and setOTM SETS
set<Id> setOpp = new set<Id>();
set<Id> setOTM = new set<Id>();
for (OpportunityTeamMember oppTeam : trigger.new) {
setOpp.add(oppTeam.OpportunityId);
setOTM.add(oppTeam.id);
}
//Loop through opportunity team members and grab Users who have these roles 'OL Assignment' or 'Sage Buddy' or 'Mentor'.
list<OpportunityTeamMember> listOTM = new list<OpportunityTeamMember>
([SELECT Id, UserId, OpportunityId, TeamMemberRole, User.Name FROM OpportunityTeamMember WHERE Id in :setOTM AND (TeamMemberRole = 'OL Assignment' OR
TeamMemberRole = 'Sage Buddy' OR TeamMemberRole = 'Mentor') ]);
// Create a map that grabs the Opportunity Id being worked with
Map<Id,Opportunity> mapOpps = new map<Id, Opportunity>([SELECT Id FROM Opportunity Where Id = :setOpp ]) ;
Opportunity tempOpp;
//Load the ID's
for(OpportunityTeamMember otm : listOTM ){
tempOpp = mapOpps.get(otm.OpportunityId);
if(otm.TeamMemberRole == 'OL Assignment') {
tempOpp.OL_Assignment1__c = otm.User.Name;
}
else if(otm.TeamMemberRole == 'Mentor') {
tempOpp.Mentor__c = otm.User.Name;
}
else if(otm.TeamMemberRole == 'Sage Buddy') {
tempOpp.Sage_Buddy__c = otm.User.Name;
}
}
// Load values
update mapOpps.values();
}
Thank you!
All Answers
If not I would suggest you to go through the below links to know how you can create test class for Triggers :-
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
http://teachmesalesforce.wordpress.com/2011/05/07/how-to-write-a-trigger-test/
http://techman97.wordpress.com/2012/07/18/how-to-write-a-basic-apex-trigger/
If this helps,please mark this as best answer to help others :)
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods