You need to sign in to do that
Don't have an account?
Jose María Nicolás Arfelis
Looking for help to write a test class for a case custom controller (urgent)
Hi all,
I hope someone can help me here as my knowledge in APEX is rudimentary but willing to learn very much.
I was wondering how would the test class to this APEX code of a custom Case controller look like:
This code is about inserting a case with the values given in the VF form for the fields Postgraduate Course, FirstName, LastName, Email, Type of case, Reason.
I would appreciate any orientation
I hope someone can help me here as my knowledge in APEX is rudimentary but willing to learn very much.
I was wondering how would the test class to this APEX code of a custom Case controller look like:
public class case_controller { public case_controller(ApexPages.StandardController controller) { } public String case_FirstName{get;set;} public String case_LastName{get;set;} public String case_Email{get;set;} public String casetype_Esp{get;set;} public String casetype_Cat{get;set;} public String casetype_En{get;set;} public String userLanguage{get;set;} public Boolean showCaptchaField {get;set;} // Variables para control de errores public Boolean show_error{get;set;} public Boolean error_dni{get;set;} public Boolean error_no_existe{get;set;} public Boolean error_dni_case{get;set;} public String phone_prefix{get;set;} public Account student{get;set;} public Case incident{get;set;} public String array_values{get;set;} public String areaSelected{get;set;} public String areaSelectedEsp{get;set;} public String areaSelectedEn{get;set;} public String areaSelectedCat{get;set;} Public Product2 postgraduatecourseCaso{get;set;} public String postgraduatecourseSelected{get;set;} public String postgraduatecourseSelectedText{get;set;} public List<SelectOption> casetypeOptionsEsp{get;set;} public List<SelectOption> casetypeOptionsEn{get;set;} public List<SelectOption> casetypeOptionsCat{get;set;} public List<SelectOption> motivocasoOptionsEsp{get;set;} public List<SelectOption> motivocasoOptionsEn{get;set;} public List<SelectOption> motivocasoOptionsCat{get;set;} public String IdentificationType_Esp{get;set;} public String IdentificationType_En{get;set;} public String IdentificationType_Cat{get;set;} public List<SelectOption> identificationOptionsEsp{get;set;} public List<SelectOption> identificationOptionsEn{get;set;} public List<SelectOption> identificationOptionsCat{get;set;} public List<SelectOption> areaOptionsEsp{get;set;} public List<SelectOption> areaOptionsEn{get;set;} public List<SelectOption> areaOptionsCat{get;set;} public List<SelectOption> postgraduatecourseOptions{ get{ String areaSelected = 'none'; if(userLanguage == 'Es') areaSelected = areaSelectedEsp; else if(userLanguage == 'En') areaSelected = areaSelectedEn; else if(userLanguage == 'Cat') areaSelected = areaSelectedCat; postgraduatecourseOptions = FormUtils.getpostgraduatecourseOpt(areaSelected, userLanguage); return postgraduatecourseOptions; }set; } private void resetErrors(){ show_error = false; error_dni = false; error_no_existe = false; error_dni_case = false; } public case_controller(){ incident = new Case(); resetErrors(); getListOptions(); // El captcha es mostrado sólo cuando la página está en la Web, no si la página se usa para registrar casos en la misma aplicación showCaptchaField = !UserUtils.isCurrentUserProfileSecretariaTecnica(); } // Registrar un caso public pageReference case_submit(){ Savepoint sp = Database.setSavepoint(); String language; try{ if (userLanguage =='En'){ language = 'English'; incident.preferred_language__c = 'English'; incident.Identification_number_type__c = IdentificationType_En; //incident.DNI__c = IdentificationNumber_En; incident.Type = casetype_En; //incident.Reason = motivocaso_En; } else if (userLanguage =='Cat'){ language = 'Catalan'; incident.preferred_language__c = 'Catalan'; incident.Identification_number_type__c = IdentificationType_Cat; //incident.DNI__c = IdentificationNumber_Cat; incident.Type = casetype_Cat; //incident.Reason = motivocaso_Cat; } else{ language = 'Spanish'; incident.preferred_language__c = 'Spanish'; incident.Identification_number_type__c = IdentificationType_Esp; //incident.DNI__c = IdentificationNumber_Esp; incident.Type = casetype_Esp; //incident.Reason = motivocaso_Esp; } System.debug('*************** case forms ///// incident '+ incident); //Preparing the data to create a case insert(incident); }catch(Exception e){ system.debug('Exception :' + e); } pageReference pageRef = new PageReference('/apex/case_answer_form'); pageRef.getParameters().put('type','case_form'); pageRef.getParameters().put('id',student.id); pageRef.getParameters().put('lng', userLanguage); return pageRef; } /**TODO: sacarlo a clase Utils private Id getAccountIdFromDNI(String dni){ Account acc = new Account(); list<Account> accountList = [Select id, FirstName, LastName, DNI__c From Account Where DNI__c = : dni]; if (accountList != null && accountList.size()>0){ acc = accountList[0]; } return acc.Id; }*/
This code is about inserting a case with the values given in the VF form for the fields Postgraduate Course, FirstName, LastName, Email, Type of case, Reason.
I would appreciate any orientation