You need to sign in to do that
Don't have an account?
Mayank.ms
Need test class for the code coverage for the task trigger
trigger OnboardingPackage on Task (after insert) { Set<String> whatIDs = new Set<String>(); for (Task t : Trigger.new) { whatIDs.add(t.whatID); } List<Opportunity> opps = [SELECT Id, Product__c, Accounting_Platform__c,Plan__c,Billing_Cycle__c FROM Opportunity WHERE Id =: whatIDs]; List<Contact> conList = new List<Contact>([select Email from Contact where Id In (select ContactId from OpportunityContactRole where OpportunityId = :whatIDs)]); EmailTemplate et1 = [SELECT id FROM EmailTemplate WHERE Name = 'Onboarding Package Desktop included']; // Stephanie EmailTemplate et2 = [SELECT id FROM EmailTemplate WHERE Name = 'Onboarding Package Desktop not included']; //Andrew EmailTemplate et3 = [SELECT id FROM EmailTemplate WHERE Name = 'Onboarding Package Cloud']; // Andrew EmailTemplate et4 = [SELECT id FROM EmailTemplate WHERE Name = 'Onboarding Package Shiplark']; EmailTemplate et5 = [SELECT id FROM EmailTemplate WHERE Name = 'Accounting Consult']; EmailTemplate et6 = [SELECT id FROM EmailTemplate WHERE Name = 'Onboarding Package Desktop included for POS']; // Aaron EmailTemplate et7 = [SELECT id FROM EmailTemplate WHERE Name = 'Onboarding Package Desktop included for PPI']; //Andrew for(Task t:Trigger.New){ for(Opportunity o :opps){ for(Contact c: conList){ if((t.subject=='Implementation service : Install') && (o.Plan__c=='EnterpriseHosting' || o.Plan__c=='pro/premierHosting' || o.Accounting_Platform__c== 'QuickBooks Enterprise (US)' || o.Accounting_Platform__c=='NetSuite')){ sendNotification(et1.id, c.id, o.id); }else if((t.subject=='Implementation service : Install') && (o.Accounting_Platform__c=='QuickBooks POS (US)')){ sendNotification(et6.id, c.id, o.id); }else if((t.subject=='Implementation service : Install') && (o.Accounting_Platform__c=='QuickBooks Pro/Premier (US)' || o.Accounting_Platform__c== 'QuickBooks CA/UK/ZA/AU') && o.Billing_Cycle__c=='Yearly'){ sendNotification(et7.id, c.id, o.id); }else if((t.subject=='Implementation service : Install') && (o.Accounting_Platform__c=='QuickBooks Pro/Premier (US)' || o.Accounting_Platform__c== 'QuickBooks CA/UK/ZA/AU') && o.Billing_Cycle__c=='Monthly' ){ sendNotification(et2.id, c.id, o.id); }else if((t.subject=='Implementation service : Install') && (o.Accounting_Platform__c=='QuickBooks Online (US)' || o.Accounting_Platform__c== 'Xero (US)')){ sendNotification(et3.id, c.id, o.id); }else if((t.subject=='Implementation service : Install') && (o.Accounting_Platform__c=='Shiplark')){ sendNotification(et4.id, c.id, o.id); }else if(t.subject=='Implementation service : Pro Advisor'){ sendNotification(et5.id, c.id, o.id); } } } } public void sendNotification(string eTempID,string tgtObjID,string whatID){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); // CONFIGURE MAIL mail.setTemplateId(eTempID); mail.setTargetObjectId(tgtObjID); mail.setWhatId(whatID); mail.setReplyTo('customersuccess@webgility.com'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } }
All Answers
Use Map or List to get your data. So you realize only one SOQL.
Please check below post for more information on test classes
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html
Please let us know if this will help you
Thanks
Amit Chaudhary
Thanks for the reply. Now with you test class getting 61% code coverage.
Can you please help me on the trigger OnboardingPackage again. I am trying to upload a new trigger on live but I am getting error Too many SOQL queries: 101 on the OnboardingPackage trigger. I have also used Static variable for this trigger now but i am unalbe to make a code coverage for it. Can you please help on it.
Trigger: OnboardingPackage
Test Class
I am getting only 40% code coverage.
Thanks