You need to sign in to do that
Don't have an account?
kermit.thefrog
Attach pdf to Opportunity -> testCoverage ApexCode
I have a flow that helps users to create an opportunity with products. When the flow finishes I want salesforce to generate a quote (consisting of data from Account, Opportunity and OpportunityProducts). This quote is generated as a pdf and I want that this quote is attached as a pdf-file to the opportunity.
I found some useful hints to set this up, but it seems that my testclass is not covering at least 75% (just 5%). Can somebody please look into this a point me into the right direction to get this running?
ApexClass:
Many thanks!
I found some useful hints to set this up, but it seems that my testclass is not covering at least 75% (just 5%). Can somebody please look into this a point me into the right direction to get this running?
ApexClass:
public class attachPDFToOpportunity { private final Opportunity a; public attachPDFToOpportunity(ApexPages.StandardController standardPageController) { a = (Opportunity)standardPageController.getRecord(); } public PageReference attachPDF() { PageReference pdfPage = Page.wedoQuote; Blob pdfBlob; if (!Test.isRunningTest()) { pdfBlob = pdfPage.getContent(); } else { pdfBlob = Blob.valueOf('Some Text'); } Attachment attach = new Attachment(parentId = a.Id, Name = 'pdfAttachmentDemo.pdf', body = pdfBlob); insert attach; PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view(); pageWhereWeWantToGo.setRedirect(true); return pageWhereWeWantToGo; } }testClass:
@isTest private class attachPDFToOpportunityTest { //tests attachPDFToOpportunity @isTest //defines method for use during testing only static void attachPDFLogic() { //BEGIN: Some Setup Items... List<Opportunity> opportunities = new List<Opportunity>(); opportunities.add(new Opportunity(Name = 'TestOppApex', StageName = 'Qualification', CloseDate = date.today())); insert opportunities; //END: Some Setup Items... Test.startTest(); //denote testing context PageReference pageRef = Page.attachPDFToOpportunity; //create a page reference to attachPDFToAccount.page Test.setCurrentPage(pageRef); //set page context ApexPages.StandardController standardController = new ApexPages.standardController(opportunities[0]); //instantiate the standard Account object controller attachPDFToOpportunity ext = new attachPDFToOpportunity(standardController); //instantiate the extension String validationURLString = ext.attachPDF().getURL(); //get the URL that is returned after the attachPDF() method is invoked String opportunityIdAsString = Id.valueOf(opportunities[0].Id); //variable represtenting the Account record Id as a String System.assertEquals(true, validationURLString.contains(opportunityIdAsString.left(15))); //validate that the URL contains the Id of the Account record Test.stopTest(); //revert from testing context } }
Many thanks!
All Answers
How to solve this?
Many thanks for helping me!