In Sandbox i written test class code coverage will be 83%. When i am going to validate in production Environment getting fatal error 0% code coverage.Can anyone help me this one.
Apex class:
public class OrderMasterStatus {
public class OrderOutput {
@InvocableVariable(required=true)
public String sOrderStatus;
}
public class OrderInput {
@InvocableVariable(required=true)
public String sOrderNumber;
}
@InvocableMethod(label='Get Order Status')
public static List<OrderOutput> getOrderStatus(List<OrderInput> orderInputs) {
Set<String> orderNumbers = new Set<String>();
// Get the order numbers from the input
for (OrderInput orderInput : orderInputs) {
orderNumbers.add(orderInput.sOrderNumber);
}
// Get the order objects from the set of order numbers
List<Order_Master__c> orders =
[SELECT Name, Status__c FROM Order_Master__c where Name in :orderNumbers];
// Create a map of order numbers and order status values
Map<String, String> mapNameStatus = new Map<String, String>();
if (orders.size() > 0) {
for (Order_Master__c order : orders) {
mapNameStatus.put(order.Name, order.Status__c);
}
}
// Build a list of order status values for the output
List<OrderOutput> orderOutputs = new List<OrderOutput>();
for (OrderInput orderInput : orderInputs) {
OrderOutput orderOutput = new OrderOutput();
// Do we have a status for this order number?
if (mapNameStatus.containsKey(orderInput.sOrderNumber)) {
// If so, then add the status
orderOutput.sOrderStatus = mapNameStatus.get(orderInput.sOrderNumber);
} else {
// If not, then add an unknown status value
orderOutput.sOrderStatus = 'Order not found';
}
orderOutputs.add(orderOutput);
}
return orderOutputs;
}
}
Test class:
@istest
public class OrderMasterStatusTest {
@testSetup
static void setupTestData(){
Order_Master__c Om = new Order_Master__c();
Om.Status__c = 'New';
insert Om;
Order_Master__c Order = [Select Id,Name,Status__c From Order_Master__c Where Id =: Om.Id];
}
static testMethod void TestMethod1(){
test.startTest();
OrderMasterStatus.OrderInput input = new OrderMasterStatus.OrderInput();
input.sOrderNumber = 'OM-202009-5';
List<OrderMasterStatus.OrderInput> listInput = new List<OrderMasterStatus.OrderInput>();
listInput.add(input);
OrderMasterStatus.getOrderStatus(listInput);
}
}
6 respuestas
Hi Lakhan,
I am not checking the code coverage in production. When i am going to validate the change set that time i am getting 0% code