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

anyone please help me to write test class for the below apex class..
public class NewClass {
public static ServicePower.spLogin fetchLoginInfo() {
ServicePower.spLogin servicePowerLogin = new ServicePower.spLogin();
String orgId = UserInfo.getOrganizationId().subString(0,15);
ServicePower_Credentials__c creds = ServicePower_Credentials__c.getValues(orgId);
String spUser = creds.SpUser__c;
String dbUser = creds.DBUser__c;
String dbPassWord = creds.DBPassword__c;
servicePowerLogin.databaseUser = dbUser;
servicePowerLogin.password = dbPassWord;
servicePowerLogin.spUser = spUser;
return servicePowerLogin;
}
public static ServicePower.TimeRequest mapJobChangeFinishTimeRequest(String woName, String finishDateTime) {
ServicePower.TimeRequest request= new ServicePower.TimeRequest();
request.login = fetchLoginInfo();
request.jobId = woName;
request.finishtime = finishDateTime;
return request;
}
public static void SPowerUpdateEndTime(List<S_Order__c> woList){
Map<String, String> woNameTimeMap = new Map<String, String>();
List<String> woNameList = new List<String>();
Datetime woFinishTime;
for(S_Order__c wo : woList)
{
if (wo.Update_Duration__c != null && wo.Add_Subtract_Minutes__c != null )
{
woFinishTime = wo.S__Scheduled_Date_Time__c.addSeconds(Integer.valueOf(wo.S__Serv_Duration__c));
System.debug('order Current Finish Time: ' + woFinishTime);
DateTime newDateTime;
List<String> woString;
if (wo.Update_Duration__c == 'Add')
newDateTime = wo.Scheduled_End__c.addMinutes((Integer)wo.Add_Subtract_Minutes__c);
else
newDateTime = wo.Scheduled_End__c.addMinutes((Integer)wo.Add_Subtract_Minutes__c * -1);
woNameList.add(wo.Name);
woNameTimeMap.put(wo.Name, newDateTime.formatgmt('yyyy-MM-dd\'T\'HH:mm'));
wo.S__Opti_Status__c = 'OPT_PENDING';
}
}
if (woNameTimeMap.size() > 0)
updateEndTime(woNameTimeMap, woNameList);
}
@future(callout=true)
public static void updateEndTime(Map<String, String> nameTimeMap, List<String> woNameList){
try{
for (String woName: woNameList){
String newDateTime = nameTimeMap.get(woName);
ServicePower.TimeRequest request = mapJobChangeFinishTimeRequest(woName, newDateTime);
System.debug('This is the request');
System.debug(request);
S_ServicePower_Service2.sp objSP = new S_ServicePower_Service2.sp();
ServicePower.StandardResponse response= objSP.ChangeJobFinishTime(request);
System.debug('This is the response ' + response);
ServicePower.ReturnCode returnCode = response.result;
S_Order__c wo = [select S__Opti_Status__c, S__Opti_Error__c, Update_Duration__c, Add_Subtract_Minutes__c from S_Order__c where name =: woName];
if(S_SP_ErrorCodesMapper.isSuccess(returnCode.code)){
wo.S__Opti_Status__c = 'OPT_COMPLETED';
}else{
wo.S__Opti_Status__c = 'OPT_ERROR';
}
String errorText = 'Return Code:' + returnCode.code + ' | Return Type:' + returnCode.type_x + ' | Return Note:' + returnCode.errNote + ' | Return Msg:' + S_SP_ErrorCodesMapper.getStatusMsg(returnCode.code);
SM.WSCH_CommonUtils.setOptimizerErrorText(wo, errorText);
wo.Update_Duration__c = null;
wo.Add_Subtract_Minutes__c = null;
update wo;
}
}catch(Exception e){
system.debug('Exception occured in updateEndTime() ' + e.getMessage());
}
}
}
public static ServicePower.spLogin fetchLoginInfo() {
ServicePower.spLogin servicePowerLogin = new ServicePower.spLogin();
String orgId = UserInfo.getOrganizationId().subString(0,15);
ServicePower_Credentials__c creds = ServicePower_Credentials__c.getValues(orgId);
String spUser = creds.SpUser__c;
String dbUser = creds.DBUser__c;
String dbPassWord = creds.DBPassword__c;
servicePowerLogin.databaseUser = dbUser;
servicePowerLogin.password = dbPassWord;
servicePowerLogin.spUser = spUser;
return servicePowerLogin;
}
public static ServicePower.TimeRequest mapJobChangeFinishTimeRequest(String woName, String finishDateTime) {
ServicePower.TimeRequest request= new ServicePower.TimeRequest();
request.login = fetchLoginInfo();
request.jobId = woName;
request.finishtime = finishDateTime;
return request;
}
public static void SPowerUpdateEndTime(List<S_Order__c> woList){
Map<String, String> woNameTimeMap = new Map<String, String>();
List<String> woNameList = new List<String>();
Datetime woFinishTime;
for(S_Order__c wo : woList)
{
if (wo.Update_Duration__c != null && wo.Add_Subtract_Minutes__c != null )
{
woFinishTime = wo.S__Scheduled_Date_Time__c.addSeconds(Integer.valueOf(wo.S__Serv_Duration__c));
System.debug('order Current Finish Time: ' + woFinishTime);
DateTime newDateTime;
List<String> woString;
if (wo.Update_Duration__c == 'Add')
newDateTime = wo.Scheduled_End__c.addMinutes((Integer)wo.Add_Subtract_Minutes__c);
else
newDateTime = wo.Scheduled_End__c.addMinutes((Integer)wo.Add_Subtract_Minutes__c * -1);
woNameList.add(wo.Name);
woNameTimeMap.put(wo.Name, newDateTime.formatgmt('yyyy-MM-dd\'T\'HH:mm'));
wo.S__Opti_Status__c = 'OPT_PENDING';
}
}
if (woNameTimeMap.size() > 0)
updateEndTime(woNameTimeMap, woNameList);
}
@future(callout=true)
public static void updateEndTime(Map<String, String> nameTimeMap, List<String> woNameList){
try{
for (String woName: woNameList){
String newDateTime = nameTimeMap.get(woName);
ServicePower.TimeRequest request = mapJobChangeFinishTimeRequest(woName, newDateTime);
System.debug('This is the request');
System.debug(request);
S_ServicePower_Service2.sp objSP = new S_ServicePower_Service2.sp();
ServicePower.StandardResponse response= objSP.ChangeJobFinishTime(request);
System.debug('This is the response ' + response);
ServicePower.ReturnCode returnCode = response.result;
S_Order__c wo = [select S__Opti_Status__c, S__Opti_Error__c, Update_Duration__c, Add_Subtract_Minutes__c from S_Order__c where name =: woName];
if(S_SP_ErrorCodesMapper.isSuccess(returnCode.code)){
wo.S__Opti_Status__c = 'OPT_COMPLETED';
}else{
wo.S__Opti_Status__c = 'OPT_ERROR';
}
String errorText = 'Return Code:' + returnCode.code + ' | Return Type:' + returnCode.type_x + ' | Return Note:' + returnCode.errNote + ' | Return Msg:' + S_SP_ErrorCodesMapper.getStatusMsg(returnCode.code);
SM.WSCH_CommonUtils.setOptimizerErrorText(wo, errorText);
wo.Update_Duration__c = null;
wo.Add_Subtract_Minutes__c = null;
update wo;
}
}catch(Exception e){
system.debug('Exception occured in updateEndTime() ' + e.getMessage());
}
}
}
Hi Raj,
I tried but it's not working at all.. even getting error on line 33..can't call string to date...
it is failing and code coverage is 0%
Thank you