Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- OpportunityTeam Test Class
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Opportunit yTeam Test Class
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-24-2013 02:37 PM
We want to be able to send a simple email notificaiton when ever a member is added to an Opportunity Team, that gives a link. Below is the working trigger we have in the sandbox, but I need help writing a APEX Test Class that will cover atleast 75% of the code before I can deploy it. The trigger works perfectly, but any help on how to write a test class would be appreciated.
trigger EmailTeamMember on OpportunityTeamMember (after insert) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
for (OpportunityTeamMember o : trigger.new) {
String[] showID = new String[] {o.UserID};
List<User> u = [SELECT Id, Name, Email, BID_Billing_Burden__c FROM User WHERE Id in :showID];
String[] toAddresses = new String[] {u[0].email};
String[] oppID = new String[] {o.OpportunityID};
if (o.User_Office__c=='LOG')
{
mail.setToAddresses(toAddresses);
mail.setReplyTo ('noreply@salesforce.com');
mail.setSenderDisplayname('Salesforce Support');
mail.setSubject('Added to an Opportunity Team ');
mail.setUseSignature(false);
mail.setPlainTextBody('You have been added to an Opportunity Team ');
mail.setHtmlBody('You have been added to an Opportunity Team:<b><p><p/> '+
'To view that opportunity <a href=https://na3.salesforce.com/'+o.OpportunityID+'>click here.</a>');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
}Thanks again!
Solved! Go to Solution.
Re: Opportunit yTeam Test Class
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-25-2013 01:16 AM
Hi Cambart,
try below :-
@IsTest(SeeAllData=true)
publci class testEmailTeamMember {
static testmethod void MyUnitTest(){
User u = [Select Id, Name, Email from User where name='Vinit Kumar']; // Vinit Kumar is a user in my org
Opportunity opp = new Opportunity(Name='ABC',CloseDate=system.today(),St
insert opp;
OpportunityTeamMember opm = new OpportunityTeamMember(User_Office__c = LOG,OpportunityId=opp.id,UserId=u.id);
insert opm;
}
}
If this answers your query,please mark this as solution so that it would be useful for others.

