You need to sign in to do that
Don't have an account?
SFDC Apex Dev
Could any one help to write test class for this apex class...
APEX CLASS
public class Mynewclass{
static List<St__c> lstSO = new List<St__c>();
static List<St__c> lstSOnew = new List<St__c>();
static Map<String,NewItem> fisMap = new Map<String,NewItem>();
static Map<String,NewItem> fiMap = new Map<String,NewItem>();
public Static void CreateStObjRec(List<SC__Order__c> SoList){
List<NewItem> lstNew = new List<NewItem>();
Map<String,SC__Order__c> woMap = new Map<String,SC__Order__c>();
Map<String,St__c> soMap = new Map<String,St__c>();
integer lstctr =0;
for(SC__Order__c SO : SoList){
lstctr=lstctr+1;
system.debug('SO.Send_Trigger_Status__c '+SO.Send_Trigger_Status__c);
system.debug('SO.SC__Order_Status__c '+SO.SC__Order_Status__c);
system.debug('SO.SC__Order_Type__c '+SO.SC__Order_Type__c);
system.debug('SO.Follow_Up__c '+SO.Follow_Up__c);
system.debug('SO.Pro_Services_Inc__c '+SO.Pro_Services_Inc__c);
system.debug('SO.Opportunity_ID__c '+SO.Opportunity_ID__c);
if (SO.Send_Trigger_Status__c == 'Not Requested' && SO.SC__Order_Status__c != 'DONE' && SO.SC__Order_Type__c.containsIgnoreCase('install') && SO.Follow_Up__c == false && !String.isBlank(String.valueOf(SO.Pro_Services_Inc__c)) && !String.isBlank(SO.Opportunity_ID__c) && (SO.Opportunity_ID__c.length()==18 || SO.Opportunity_ID__c.length()==15 )){
system.debug(' system.debug at 29');
if ((!String.isBlank(SO.SC__Country__c)) && (!String.isBlank(String.ValueOf(SM_Route_Settings__c.getValues(SO.SC__Country__c)))) && SM_Route_Settings__c.getValues(SO.SC__Country__c).Valid_for_Proj__c == true){
system.debug(' Inside loop ');
SO.Send_Trigger_Status__c = 'Send Requested';
NewItem post = new NewItem();
post.ParentId = SO.ID;
post.Body = 'Staging Object Record added for Wrk '+ SO.Name +' for interfacing to CM' +'\n';
post.Body = post.Body + 'CM Send Trigger Status is ' + SO.Send_Trigger_Status__c +'\n';
post.Body = post.Body + 'Order status is ' + SO.SC__Order_Status__c +'\n';
post.Body = post.Body + 'Order Type is ' + SO.SC__Order_Type__c +'\n';
post.Body = post.Body + 'Pro Services Inc is ' + SO.Pro_Services_Inc__c +'\n';
post.Body = post.Body + 'Opportunity ID is ' + SO.Opportunity_ID__c +'\n';
post.Body = post.Body + 'Country is ' + SO.SC__Country__c ;
if (!String.isBlank(SO.ID))
{
lstNew.add(post);
}
system.debug(' SO DETAILS ============== : '+SO);
fiMap.put(SO.OwnerId+lstctr.format(),post);
system.debug('fismap details >>>>>>>>'+fiMap);
system.debug('SO.name+lstctr.format() === '+SO.OwnerId+lstctr.format());
St__c SO = new St__c();
SO.RecordTypeId = getRecordType('Wrk');
SO.Opportunity_ID__c = SO.Opportunity_ID__c;
SO.Order_ID__c = SO.ID;
SO.Order_Number__c = SO.ID;
lstSO.add(SO);
soMap.put(wo.OwnerId+lstctr.format(),SO);
woMap.put(wo.OwnerId+lstctr.format(),SO);
}
else if ((String.isBlank(SO.SC__Country__c)) || (String.isBlank(String.ValueOf(SM_Route_Settings__c.getValues(SO.SC__Country__c)))) || SM_Route_Settings__c.getValues(SO.SC__Country__c).Valid_for_Proj__c == false){
system.debug('Inside not meet criteria at 73===========================');
SO.Send_Trigger_Status__c = 'Does Not Meet Criteria';
NewItem post = new NewItem();
post.ParentId = SO.ID;
post.Body = 'Wrk '+ SO.Name +' does not meet criteria for interfacing to CM'+'\n';
post.Body = post.Body + 'CM Send Trigger Status is ' + SO.Send_Trigger_Status__c +'\n';
post.Body = post.Body + 'Order status is ' + SO.SC__Order_Status__c +'\n';
post.Body = post.Body + 'Order Type is ' + SO.SC__Order_Type__c +'\n';
post.Body = post.Body + 'Pro Services Inc is ' + SO.Pro_Services_Inc__c +'\n';
post.Body = post.Body + 'Opportunity ID is ' + SO.Opportunity_ID__c +'\n';
post.Body = post.Body + 'Country is ' + SO.SC__Country__c;
if (!String.isBlank(SO.ID))
{
lstNew.add(post);
}
fiMap.put(wo.OwnerId+lstctr.format(),post);
}
}
if (!lstNew.isEmpty()){
upsert lstNew;
}
if (!soMap.isEmpty()){
Insert soMap.values();
}
system.debug('soMap Values : '+ soMap);
system.debug('fiMap Values == : '+ fiMap);
for(String mapKey: soMap.keySet()){
SC__Order__c temp = SOMap.get(mapKey);
St__c sso = soMap.get(mapKey);
temp.Obj_Name__c = sso.ID;
SOMap.put(mapkey,temp);
NewItem fi = fiMap.get(mapKey);
if (fi != null){
system.debug('New Item '+fi);
system.debug('sso.id == '+ sso.id);
if (!String.isBlank(sso.id)){
if (String.isBlank(fi.Parentid)){
system.debug('debug at 191 line ==');
fi.Parentid = sso.id;
fisMap.put(sso.id,fi);
}
}
}
}
system.debug('fisMap values ================'+fisMap.values());
}
}
public class Mynewclass{
static List<St__c> lstSO = new List<St__c>();
static List<St__c> lstSOnew = new List<St__c>();
static Map<String,NewItem> fisMap = new Map<String,NewItem>();
static Map<String,NewItem> fiMap = new Map<String,NewItem>();
public Static void CreateStObjRec(List<SC__Order__c> SoList){
List<NewItem> lstNew = new List<NewItem>();
Map<String,SC__Order__c> woMap = new Map<String,SC__Order__c>();
Map<String,St__c> soMap = new Map<String,St__c>();
integer lstctr =0;
for(SC__Order__c SO : SoList){
lstctr=lstctr+1;
system.debug('SO.Send_Trigger_Status__c '+SO.Send_Trigger_Status__c);
system.debug('SO.SC__Order_Status__c '+SO.SC__Order_Status__c);
system.debug('SO.SC__Order_Type__c '+SO.SC__Order_Type__c);
system.debug('SO.Follow_Up__c '+SO.Follow_Up__c);
system.debug('SO.Pro_Services_Inc__c '+SO.Pro_Services_Inc__c);
system.debug('SO.Opportunity_ID__c '+SO.Opportunity_ID__c);
if (SO.Send_Trigger_Status__c == 'Not Requested' && SO.SC__Order_Status__c != 'DONE' && SO.SC__Order_Type__c.containsIgnoreCase('install') && SO.Follow_Up__c == false && !String.isBlank(String.valueOf(SO.Pro_Services_Inc__c)) && !String.isBlank(SO.Opportunity_ID__c) && (SO.Opportunity_ID__c.length()==18 || SO.Opportunity_ID__c.length()==15 )){
system.debug(' system.debug at 29');
if ((!String.isBlank(SO.SC__Country__c)) && (!String.isBlank(String.ValueOf(SM_Route_Settings__c.getValues(SO.SC__Country__c)))) && SM_Route_Settings__c.getValues(SO.SC__Country__c).Valid_for_Proj__c == true){
system.debug(' Inside loop ');
SO.Send_Trigger_Status__c = 'Send Requested';
NewItem post = new NewItem();
post.ParentId = SO.ID;
post.Body = 'Staging Object Record added for Wrk '+ SO.Name +' for interfacing to CM' +'\n';
post.Body = post.Body + 'CM Send Trigger Status is ' + SO.Send_Trigger_Status__c +'\n';
post.Body = post.Body + 'Order status is ' + SO.SC__Order_Status__c +'\n';
post.Body = post.Body + 'Order Type is ' + SO.SC__Order_Type__c +'\n';
post.Body = post.Body + 'Pro Services Inc is ' + SO.Pro_Services_Inc__c +'\n';
post.Body = post.Body + 'Opportunity ID is ' + SO.Opportunity_ID__c +'\n';
post.Body = post.Body + 'Country is ' + SO.SC__Country__c ;
if (!String.isBlank(SO.ID))
{
lstNew.add(post);
}
system.debug(' SO DETAILS ============== : '+SO);
fiMap.put(SO.OwnerId+lstctr.format(),post);
system.debug('fismap details >>>>>>>>'+fiMap);
system.debug('SO.name+lstctr.format() === '+SO.OwnerId+lstctr.format());
St__c SO = new St__c();
SO.RecordTypeId = getRecordType('Wrk');
SO.Opportunity_ID__c = SO.Opportunity_ID__c;
SO.Order_ID__c = SO.ID;
SO.Order_Number__c = SO.ID;
lstSO.add(SO);
soMap.put(wo.OwnerId+lstctr.format(),SO);
woMap.put(wo.OwnerId+lstctr.format(),SO);
}
else if ((String.isBlank(SO.SC__Country__c)) || (String.isBlank(String.ValueOf(SM_Route_Settings__c.getValues(SO.SC__Country__c)))) || SM_Route_Settings__c.getValues(SO.SC__Country__c).Valid_for_Proj__c == false){
system.debug('Inside not meet criteria at 73===========================');
SO.Send_Trigger_Status__c = 'Does Not Meet Criteria';
NewItem post = new NewItem();
post.ParentId = SO.ID;
post.Body = 'Wrk '+ SO.Name +' does not meet criteria for interfacing to CM'+'\n';
post.Body = post.Body + 'CM Send Trigger Status is ' + SO.Send_Trigger_Status__c +'\n';
post.Body = post.Body + 'Order status is ' + SO.SC__Order_Status__c +'\n';
post.Body = post.Body + 'Order Type is ' + SO.SC__Order_Type__c +'\n';
post.Body = post.Body + 'Pro Services Inc is ' + SO.Pro_Services_Inc__c +'\n';
post.Body = post.Body + 'Opportunity ID is ' + SO.Opportunity_ID__c +'\n';
post.Body = post.Body + 'Country is ' + SO.SC__Country__c;
if (!String.isBlank(SO.ID))
{
lstNew.add(post);
}
fiMap.put(wo.OwnerId+lstctr.format(),post);
}
}
if (!lstNew.isEmpty()){
upsert lstNew;
}
if (!soMap.isEmpty()){
Insert soMap.values();
}
system.debug('soMap Values : '+ soMap);
system.debug('fiMap Values == : '+ fiMap);
for(String mapKey: soMap.keySet()){
SC__Order__c temp = SOMap.get(mapKey);
St__c sso = soMap.get(mapKey);
temp.Obj_Name__c = sso.ID;
SOMap.put(mapkey,temp);
NewItem fi = fiMap.get(mapKey);
if (fi != null){
system.debug('New Item '+fi);
system.debug('sso.id == '+ sso.id);
if (!String.isBlank(sso.id)){
if (String.isBlank(fi.Parentid)){
system.debug('debug at 191 line ==');
fi.Parentid = sso.id;
fisMap.put(sso.id,fi);
}
}
}
}
system.debug('fisMap values ================'+fisMap.values());
}
}
Check once below sample code :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
Salesforce Freelance Consultant/Developer/Administrator
@For Salesforce Project Support: varaprasad4sfdc@gmail.com
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1