You need to sign in to do that
Don't have an account?
Chiho Sullivan
help with apexpages.addmessage test/code coverate
been at this for hours and can't seem to figure out why my test class isn't covering the following controller code: } catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new application.'));
return null;
}.
i do have a few workflow rules that are active but the initial insert of a new record would not fire any of these off...would that have an impact?
Controller is
public class KFGCreateTrainingApplicationController {
public Applications__c applications {get; set;}
// blank constructor
public KFGCreateTrainingApplicationController() {
applications = new Applications__c();
}
// save button is clicked
public PageReference save() {
try {
upsert(applications); // inserts the new record into the database
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new application.'));
return null;
}
// if successfully inserted new application, then displays the thank you page.
return Page.TrainingApplicationThankYou;
}
}
Test Is:
@isTest
public with sharing class KFGCreateTrainingAppControllerTest {
//==================== TEST METHOD(s) ======================================
static testMethod void KFGCreateTrainingAppControllerTest() {
Applications__c newApplications = new Applications__c();
// Test insert Applications__c
newApplications.Application_Date__c = Date.Today();
newApplications.Online_Application__c = 'Yes';
newApplications.Class_Number_Being_Applied_For__c = 1;
newApplications.Applicant_First_Name__c = 'TestFirstName';
newApplications.Applicant_Last_Name__c = 'TestLastName';
newApplications.Age__c = 24;
newApplications.Gender__c = 'Female';
newApplications.Race__c = 'Latino/Hispanic';
newApplications.Email__c = 'testreferrer@test.com';
newApplications.State__c = 'ca';
newApplications.Are_You_A_Current_or_Former_Foster_Youth__c = 'Yes';
newApplications.Are_You_a_Domestic_Violence_Victim__c = 'Yes';
newApplications.Did_You_Attend_College__c = 'No';
newApplications.Did_You_Attend_High_School__c = 'No';
newApplications.Have_You_Had_Vocational_Training__c = 'No';
newApplications.Did_You_Serve_in_the_Armed_Forces__c = 'No';
newApplications.Do_You_Currently_Have_Income__c = 'No';
newApplications.Do_You_Have_a_History_of_Substance_Abuse__c = 'None';
newApplications.Do_You_Have_a_Mental_Health_Diagnosis__c = 'No';
newApplications.Do_You_Have_a_Physical_Disorder__c = 'No';
newApplications.Do_You_Work_With_a_Case_Manager_Program__c = 'No';
newApplications.How_Did_You_Hear_About_the_Program__c = 'Agency Referral';
newApplications.Number_of_People_You_Financially_Support__c = '1';
newApplications.What_is_Your_Housing_Status__c = 'Rent';
newApplications.What_is_Your_Legal_History__c = 'None';
insert newApplications;
KFGCreateTrainingApplicationController controller=new KFGCreateTrainingApplicationController();
controller.save();
}
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new application.'));
return null;
}.
i do have a few workflow rules that are active but the initial insert of a new record would not fire any of these off...would that have an impact?
Controller is
public class KFGCreateTrainingApplicationController {
public Applications__c applications {get; set;}
// blank constructor
public KFGCreateTrainingApplicationController() {
applications = new Applications__c();
}
// save button is clicked
public PageReference save() {
try {
upsert(applications); // inserts the new record into the database
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new application.'));
return null;
}
// if successfully inserted new application, then displays the thank you page.
return Page.TrainingApplicationThankYou;
}
}
Test Is:
@isTest
public with sharing class KFGCreateTrainingAppControllerTest {
//==================== TEST METHOD(s) ======================================
static testMethod void KFGCreateTrainingAppControllerTest() {
Applications__c newApplications = new Applications__c();
// Test insert Applications__c
newApplications.Application_Date__c = Date.Today();
newApplications.Online_Application__c = 'Yes';
newApplications.Class_Number_Being_Applied_For__c = 1;
newApplications.Applicant_First_Name__c = 'TestFirstName';
newApplications.Applicant_Last_Name__c = 'TestLastName';
newApplications.Age__c = 24;
newApplications.Gender__c = 'Female';
newApplications.Race__c = 'Latino/Hispanic';
newApplications.Email__c = 'testreferrer@test.com';
newApplications.State__c = 'ca';
newApplications.Are_You_A_Current_or_Former_Foster_Youth__c = 'Yes';
newApplications.Are_You_a_Domestic_Violence_Victim__c = 'Yes';
newApplications.Did_You_Attend_College__c = 'No';
newApplications.Did_You_Attend_High_School__c = 'No';
newApplications.Have_You_Had_Vocational_Training__c = 'No';
newApplications.Did_You_Serve_in_the_Armed_Forces__c = 'No';
newApplications.Do_You_Currently_Have_Income__c = 'No';
newApplications.Do_You_Have_a_History_of_Substance_Abuse__c = 'None';
newApplications.Do_You_Have_a_Mental_Health_Diagnosis__c = 'No';
newApplications.Do_You_Have_a_Physical_Disorder__c = 'No';
newApplications.Do_You_Work_With_a_Case_Manager_Program__c = 'No';
newApplications.How_Did_You_Hear_About_the_Program__c = 'Agency Referral';
newApplications.Number_of_People_You_Financially_Support__c = '1';
newApplications.What_is_Your_Housing_Status__c = 'Rent';
newApplications.What_is_Your_Legal_History__c = 'None';
insert newApplications;
KFGCreateTrainingApplicationController controller=new KFGCreateTrainingApplicationController();
controller.save();
}
}
Thanks,
1. applications are logged into salesforce via VF page...no fields used in process builder are needed or included in the form to log the application
2. user reviews applications logged, when appropriate and based on statuses selected by the user, use process builder to create a student record. none of the process builder workflow rules would be triggered when the application is created only when the record is edited to update the status