You need to sign in to do that
Don't have an account?
forceapp
Test class covered 42% need more coverage from ur help.
trigger emailquotetrig on Opportunity (after insert, after update) { List<quote> quotelist=new List<quote>(); for(opportunity opp:trigger.new){ quote q=new quote(); if(opp.StageName=='Closed Won'){ try{ q=[select status,name,id,opportunityid from quote where Status__c=true and opportunityid=:opp.id]; Messaging.reserveSingleEmailCapacity(1); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses=new String[]{'arvind.kot@gmail.com'}; mail.setToAddresses(toAddresses); mail.setReplyTo('arvind_kot@rediffmail.com'); mail.setSenderDisplayName('Salesforce Support'); mail.setSubject('Plz click on the link to view the quote record'); mail.setBccSender(false); mail.setUseSignature(false); mail.setPlainTextBody('https://ap1.salesforce.com/'+ q.id); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); }catch(system.QueryException e){ opp.adderror('Need to select a primary quote among the related quotes'); } } } } Test class covered only 42 %: @isTest private class Test_emailquotetrig { static testMethod void myUnitTest() { // TO DO: implement unit test opportunity opp=new opportunity(name='Monitors',closedate=system.today(),StageName='closed won'); insert opp; Quote obj=new Quote(name='keyboard',primary__c=true,opportunityid=opp.id); insert obj; } }
All Answers
@isTestprivate class Test_emailquotetrig {
static testMethod void myUnitTest() {
opportunity opp = new opportunity(name='forceapp',Closeddate=system.today(),StageName='Prospecting');
insert opp;
Quote qu = new Quote(name='contributor',primary__c=true,opportunityid=opp.id);
insert quo;
opportunity o =[select id from opportunity where id=:opp.id]
o.StageName='Closed Won';
update o;
but the code coverage is 89%, how 2 cover the catch block need a reply.
Try this: