Class of webservice
global with sharing class nameclassofwebservice {
webservice static responseWrapper createCustomReminder(String id, String Description) {
responseWrapper response = new responseWrapper();
if(id == null){
response.Id = id;
response.ResultCode = 'KO';
response.ResultDescription = 'Error Missing Id';
throw new WrtsException('KO - Missing Id');
}
CustomReminder__c reminder = new CustomReminder__c();
reminder.Code__c = '';
reminder.Description__c = Description;
reminder.ExecutionDateTime__c = datetime.now();
reminder.RecordId__c = id;
reminder.Status__c = 'Executed';
try {
upsert(reminder);
response.Id = reminder.id;
response.ResultCode = 'OK';
response.ResultDescription = 'CustomReminder__c Id: ' + reminder.Id + ' - Dossier Id: ' + id + ' - Description: ' + Description;
} catch (Exception e) {
response.Id = id;
response.ResultCode = 'KO';
response.ResultDescription = 'Error creation CustomReminder__c for Dossier Id: ' + id + ' - Error message: ' + e.getMessage();
}
//return JSON.serialize(response);
return response;
}
global class responseWrapper {
webservice String Id {get; set;}
webservice String ResultCode {get; set;}
webservice String ResultDescription {get; set;}
public responseWrapper(){ }
}
}
Test Class
@isTest
public class nameclassofwebserviceTest {
static testMethod void testNewWebService()
{
nameclassofwebservice.responseWrapper wsResponse = new nameclassofwebservice.responseWrapper();
wsResponse.Id = '12345df7891ersw';
wsResponse.ResultCode = 'OK';
wsResponse.ResultDescription = 'Test Descrizione';
nameclassofwebservice.createCustomReminder( '12345df7891ersw','test' );
CustomReminder__c[] cr = [select Id from CustomReminder__c where RecordId__c = '12345df7891ersw'];
System.assertEquals(cr.size(), 1);
}
}