You need to sign in to do that
Don't have an account?
Urgent: Please help in code coverage
Please help in code coverage. im able to get 34% code coverage .
Please find the below code class and test class.
Thanks...
1
public with sharing class NewOrderPageClass
2
{
3
public Id orid{get;set;}
4
// public List<id> Opids{get;set;}
5
public Order__c OppId{get;set;}
6
public List<Order_Product__c> oplist{get;set;}
7
public List<Product_Master__c> Pmid{get;set;}
8
public NewOrderPageClass(ApexPages.StandardController controller)
9
{
10
try
{
String orid=ApexPages.CurrentPage().getParameters().get('id');
oplist=new List<Order_Product__c>();
OppId=[select id,name from Order__c where id=:orid];
Pmid=[select id,name,Size_S__c,Size_L__c,Size_M__c,Size_XL__c,Price__c,Remarks__c from Product_Master__c WHERE Product_Type__c='Sales' ORDER BY CreatedDate ASC];
}
catch(Exception e)
{
system.debug(e);
}
}
public PageReference CreateOrderProduct()
{
for( Product_Master__c p:pmid)
{
try
{
if(p.Size_S__c>0||p.Size_L__c>0||p.Size_M__c>0||p.Size_XL__c>0)
{
RecordType rty = [SELECT Name, id FROM RecordType WHERE sObjectType='Order_Product__c' and name='Sales'];
System.debug('-------------------> Record Type Ids'+rty);
Order_Product__c op=new Order_Product__c(RecordTypeId=rty.id);
op.Product_Master__c=p.id;
op.Sales_Order__c=OppId.id;
op.name=p.Name;
op.Size_S__c=p.Size_S__c;
42
op.Size_M__c=p.Size_M__c;
43
op.Size_L__c=p.Size_L__c;
44
op.Size_XL__c=p.Size_XL__c;
45
/*op.quantity__c=p.Quantity__c;*/
46
insert op;
47
System.debug('-------------------> Order Products are Ids'+op);
48
oplist.add(op);
49
50
51
}
52
}
53
catch(Exception e)
54
{
55
system.debug(e);
56
}
57
}
58
PageReference reference=new PageReference('/'+OppId);
59
60
return reference;
61
}
62
63
private Static testmethod void NewOrderPageClass()
64
{
65
List<Order_Product__c> oplist=new List<Order_Product__c>();
66
Account a=new Account();
67
a.name='ravi';
68
insert a;
69
Order__c o=new Order__c();
70
o.Account__c=a.id;
71
insert o;
72
List<Product_Master__c> pmList=new List<Product_Master__c>();
73
Product_Master__c pm = new Product_Master__c (Name='ravi',Size_S__c=12,Size_M__c=13,Size_L__c=14,Size_XL__c=15,Product_Type__c='Sales');
74
pmList.add(pm);
75
/*pm.Name='ravi';
76
pm.Size_S__c=12;
77
pm.Size_M__c=13;
78
pm.Size_L__c=14;
79
pm.Size_XL__c=15;*/
80
insert pm;
81
Order_Product__c op=new Order_Product__c();
82
op.Product_Master__c=pm.id;
83
op.Sales_Order__c=o.id;
84
op.name=pm.Name;
85
op.Size_S__c=11;
86
op.Size_M__c=12;
87
op.Size_L__c=14;
88
op.Size_XL__c=15 ;
89
insert op;
90
NewOrderPageClass atc= new NewOrderPageClass(new ApexPages.StandardController(o));
91
PageReference pageRef = Page.SalesOrder;
92
Test.setCurrentPage(pageRef);
93
/* atc .CreateOrderProduct();*/
94
95
}
96
97
}