You need to sign in to do that
Don't have an account?
SFDC BUG
Web Service code Coverage improve
How can i improve code coverage of web service class 90% to 100%(line 19,58 and 64 is not cover)
global class Send_Challn_To_Accounts { public static blob b; WebService static string Send_Challn_To_Accounts(string id) { try { Challan__c qt=[Select id,Call_up_order_id__c,Division__c,Excise_Registration_No__c,Range__c,Freight_Charge_Applicable_Extra__c,Challan_id__c,Basic_Price_Each_item__c,Basic_Price_per_1000__c,Accounts_Email_Id__c,Sale_Confirmation_Order_ID__c,Account_Id__c,Account_Name__c,Company_Name__c,Account_Name__r.Name,Challan_Number__c,Sale_Confirmation_Order__r.name from Challan__c where id=:id]; PageReference pdf =new PageReference('/apex/view_challan_form?id='+id); pdf.setRedirect(true); if(Test.isRunningTest() == false){ b = pdf.getContent(); } //--------create a mail object to send a single email.-------- Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); string[] toaddress =String.valueOf(qt.Accounts_Email_Id__c).Split(','); mail.setToAddresses(toaddress); // mail.setToAddresses(new string[] {qt.email__c}); // Internal_Email_User_Id__c text fied mail.setBccAddresses(new String[] {'test@globalnest.com'}); mail.setBccSender(true); //mail.setSenderDisplayName(qt.Account_Name__c); mail.setSubject('Challan For'+' '+qt.Company_Name__c+' : '+qt.Sale_Confirmation_Order__r.name); //------------- Create the email attachment----------------- Invoice_Dispatch_details__c invoice=new Invoice_Dispatch_details__c(); // invoice=[select id,Account_Lookup__c,Purchase_Order__c from Invoice_Dispatch_details__c where Challan__c=:id]; Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName('Challan.pdf'); efa.setBody(b); //----------------------------------------------------------- mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); mail.setPlainTextBody('Hi Accounts Team, Please find the Challan for '+qt.Company_Name__c +' '+'attached to this mail.'+'\n'+'\n'+'\n'+'\n'+'Freight Charge Applicable Extra:'+qt.Freight_Charge_Applicable_Extra__c+'\n' +'Account Name:'+qt.Company_Name__c+'\n'+'SCO no:'+qt.Sale_Confirmation_Order__r.name+'\n'+'Challan No:'+qt.Challan_Number__c+'\n'+'Basic Price (Each item):'+qt.Basic_Price_Each_item__c+'\n'+'Basic Price (per 1000):'+qt.Basic_Price_per_1000__c+'\n'+'Excise Registration No:'+qt.Excise_Registration_No__c+'\n'+'Division:'+qt.Division__c+'\n'+'Range:'+qt.Range__c+'\n'+'\n'+'Thanks & Regards'+'\n'+'Care Team'); //------------------------Attach sales order to a contract-------------------- Attachment formAttach = new Attachment(); formAttach.Name = 'Challan'+qt.Account_Name__c+'.pdf'; formAttach.body = b; formAttach.ContentType='application/pdf'; formAttach.parentId =id; if (!Test.isRunningTest()) { insert formAttach; } //send the email Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } ); return 'Challan has been sent'; } catch(exception ex) { string ex1=string.valueof(ex); return ex1; } } }
@isTest private class testSend_Challn_To_Accounts { static testMethod void teSend_Challn_To_Accounts() { account a=new account(name='test',Region__c='East'); insert a; Master_Product__c mp=new Master_Product__c(name='test name',Product_Code__c='c2'); insert mp; contact c=new contact(firstname='Meenakshmi',lastname='Goswami',Designation__c='Developer',Accountid=a.id); insert c; Opportunity2__c op=new Opportunity2__c(Name='test1',Account__c=a.id,Master_Product__c=mp.id,Technical_Bid_date__c=date.Today(),Type_of_Business__c='Regular',Contact_Person__c=c.id); insert op; Opportunity_Product_Detail__c opd=new Opportunity_Product_Detail__c(Opportunity__c=op.id,Company__c=a.id,Quantity__c=1000,Height__c=12,Label_Height__c=12,Hologram_Height__c=14,Holographic_Film_Height__c=15,Multimax_Seal_Height__c=16,Sleeve_Height__c=90,Foil_Stamping_Height__c=17,Width__c=22,Label_Width__c=23,Foil_Width_for_Supplies__c=24,Hologram_Width__c=25,Holographic_Film_Width__c=27,Holographic_Strip_Width__c=28,Sleeve_Layflat_Width__c=29,Sleeve_Width__c=30,Foil_Stamping_Width__c=31,Make__c='ACR',Model__c='GT800'); insert opd; Quote__c qt=new Quote__c(Opportunity_Product_Detail__c=opd.id,Purpose_of_Sales__c='SEZ',Basic_Price_Each_item__c=23,Declaration_form_be_provided__c='No',TTR_Height__c=13,TTR_Width__c=12); insert qt; Purchase_Order__c sco=new Purchase_Order__c(Quote__c=qt.id,Opportunity__c=op.id,New_Flash_Aidc_Email_sent__c='venky@globalnest.com'); insert sco; Call_Up_Order__c call=new Call_Up_Order__c(Quote__c=qt.id,Name='test',Sale_Confirmation_Order__c=sco.id,Call_Up_Quantity__c=2); insert call; system.debug(' Call_Up_Orde details'+call); Challan__c c2=new Challan__c(Call_Up_Order__c=call.id,Sale_Confirmation_Order__c=sco.id,Challan_Date__c=system.today(),Challan_Number__c='1234'); insert c2; Blob b = Blob.valueOf('Test Data'); Attachment attachment = new Attachment(); attachment.ParentId = c2.id; attachment.Name = 'Test Attachment for Parent'; attachment.Body = b; insert(attachment); Send_Challn_To_Accounts act = new Send_Challn_To_Accounts(); Send_Challn_To_Accounts.Send_Challn_To_Accounts(c2.id); } }
Regards,
Amit Singh
GIRIKON LLC
https://sfdcpanther.wordpress.com/