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

how write test class for apex class with 75% Percentage Code Coverage
Hi Team,
I am create the apex class for tracking the Quote.....
My Apex Class is
global with sharing class InvoicePdfWsSample { webService static String generateInvoicePdf(List<Id> oppsIdList) { try { final Set<Id> oppsId = new Set<Id>(oppsIdList); final String quoteTemplateDataViewerUrl = '/quote/quoteTemplateDataViewer.apexp?id={!QuoteId}&headerHeight=100&footerHeight=100&summlid=0EH0K0000034xt6'; if (String.isBlank(quoteTemplateDataViewerUrl)) { String errorMsg = 'Invoice Template Id or Quote Template Data Viewer URL are blank, please review their values in Application Properties custom setting.'; return errorMsg; } final List<QuoteDocument> attList = new List<QuoteDocument>(); for (Opportunity opp : [ SELECT Id, ( SELECT Id, QuoteNumber, IsSyncing,Quote_Track__c,CreatedDate FROM Quotes ORDER BY CreatedDate DESC ) FROM Opportunity WHERE Id IN :oppsId ]) { if (opp.Quotes.isEmpty()) continue; Quote theQuote = null; for (Quote quoteAux : opp.Quotes) { if (quoteAux.IsSyncing) { theQuote = quoteAux; break; } } if (theQuote == null) theQuote = opp.Quotes.get(0); PageReference pageRef = new PageReference( quoteTemplateDataViewerUrl.replace('{!QuoteId}', theQuote.Id) ); attList.add( new QuoteDocument( Document = pageRef.getContent(), QuoteId = theQuote.Id ) ); theQuote.Quote_Track__c= theQuote.Quote_Track__c+ 1; update theQuote; } system.debug(attList); if (!attList.isEmpty()){ insert attList; } return ''; } catch (Exception e) { System.debug(LoggingLevel.ERROR, e.getMessage()); final String errorMsg = 'An error has occured while generating the invoice. Details:\n\n' + e.getMessage() + '\n\n' + e.getStackTraceString(); return errorMsg; } } }
My Test Class
@isTest (SeeAllData=true) public class InvoicePdfWsSampleTest { static testMethod void TestMe() { List<Id> oidl = new List<Id>(); List<Opportunity> ol = new List<Opportunity>([SELECT Id FROM Opportunity ORDER BY CreatedDate DESC LIMIT 10]); for (Opportunity o : ol){ oidl.add(o.Id); } InvoicePdfWsSample.generateInvoicePdf(oidl); } }
I getting 69% Code coverage of the test class. How can i increase the code coverage?
Please remove SeeAllData=true from class level.
Create your own test data in your test class.
Please follow below link for more details and mark this as best answer if it helps to you.
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Regards,
Prakash
nawaleprakash@gmail.com
when i remove it. It show 35%
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Please check following code once.I have not tested below code may you will get syntactical errors.
Hope this helps you!
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com