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

How to write test class for the map
public Map<String,Object> con018{
get{
if(AccountId!=null){
Map<String,Object> linkMap = new Map<String,Object>();
List<Account> or1 = [SELECT Id,Parent.Id FROM Account WHERE Id =:AccountId];
List<Account> or2 = [SELECT Id,AccountReferenceNumber__c, (SELECT vlocity_cmt__DueDate__c,BillToContact.FirstName,SNL_ActualStartDate__c,Usage_Monthly_Total_Including_VAT__c FROM orders) FROM Account WHERE Id =:or1[0].Parent.Id];
list<Order> OrderList = new List<Order>();
String ff;
for(Account a : or2)
{
for(Order c : a.Orders)
{
OrderList.add(c); // assign contact to the list
}
}
for(Order z : OrderList){
ff=z.BillToContactId;
}
List<Contact> Con=[Select Firstname from Contact where Id=:ff];
String refno='refno';
String refnoval = String.valueOf(or2[0].get('AccountReferenceNumber__c'));
linkMap.put(refno,refnoval);
String fname = 'fname';
String fnameval = String.valueOf(Con[0].get('FirstName'));
linkMap.put(fname,fnameval);
String asd = 'asd';
DateTime asdval = OrderList[0].SNL_ActualStartDate__c;
linkMap.put(asd,asdval);
String amnt = 'amnt';
String amntval = String.valueOf(OrderList[0].Usage_Monthly_Total_Including_VAT__c);
linkMap.put(amnt,amntval);
String dd = 'dd';
DateTime ddval = OrderList[0].vlocity_cmt__DueDate__c;
linkMap.put(dd,ddval);
return linkMap;
}else{
return null;
}
}
set;
}
get{
if(AccountId!=null){
Map<String,Object> linkMap = new Map<String,Object>();
List<Account> or1 = [SELECT Id,Parent.Id FROM Account WHERE Id =:AccountId];
List<Account> or2 = [SELECT Id,AccountReferenceNumber__c, (SELECT vlocity_cmt__DueDate__c,BillToContact.FirstName,SNL_ActualStartDate__c,Usage_Monthly_Total_Including_VAT__c FROM orders) FROM Account WHERE Id =:or1[0].Parent.Id];
list<Order> OrderList = new List<Order>();
String ff;
for(Account a : or2)
{
for(Order c : a.Orders)
{
OrderList.add(c); // assign contact to the list
}
}
for(Order z : OrderList){
ff=z.BillToContactId;
}
List<Contact> Con=[Select Firstname from Contact where Id=:ff];
String refno='refno';
String refnoval = String.valueOf(or2[0].get('AccountReferenceNumber__c'));
linkMap.put(refno,refnoval);
String fname = 'fname';
String fnameval = String.valueOf(Con[0].get('FirstName'));
linkMap.put(fname,fnameval);
String asd = 'asd';
DateTime asdval = OrderList[0].SNL_ActualStartDate__c;
linkMap.put(asd,asdval);
String amnt = 'amnt';
String amntval = String.valueOf(OrderList[0].Usage_Monthly_Total_Including_VAT__c);
linkMap.put(amnt,amntval);
String dd = 'dd';
DateTime ddval = OrderList[0].vlocity_cmt__DueDate__c;
linkMap.put(dd,ddval);
return linkMap;
}else{
return null;
}
}
set;
}
First of all, we need to identity which kind of Map we are using in our class.
There are two types of Map which we can cover using test class.
1) Private Map - Map is declared as Private or inside a method which is not accessible in Test Class. We can not pass values by test class.
In order to cover private map, first we need to find the line where we put values into map in our class like mapName.put(). We need to focus only on this line. If put() method of Map is under any IF condition or For loop. Please make sure that IF condition and For loop is covered first then only map will be covered.
2) Public Map - Map is declared as Public which can be accessible in Test Class. We can pass values by Test class.
In order to cover public map, we can simply access this map in our test class and put values directly it. It can also be a parameterized map which is passed inside a method like
Public Void Method_Name( Map< Id, Account > acc );
We can put values while calling this method in our test class.
For more guidance on writing test classes:
https://www.infallibletechie.com/2018/08/salesfore-apex-test-class-best-pracitces.html
Hope above information helps. Please mark as Best Answer so that it can help others in future.
Thanks.
Hi Please find the solution.
Do the needful changes.
Please mark it as the Best Answer so that other people would take reference from it.
Thank You
It is showing the following error.
"Method does not exist or incorrect signature: void con018() from the type Art_Order" here Art_Order is my controller
hi
Are you still looking for answer?