You need to sign in to do that
Don't have an account?
Nitzan Marinov
Deployment Validation failed but no explanation
Hi all,
I made some changes to Apex class code and all tests come back without a failure. However, when I try to deploy and run the validation, I still get below 75% coverege but there is no explanation. Does anyone know how to resolve this?
Thanks
Nitzan
I made some changes to Apex class code and all tests come back without a failure. However, when I try to deploy and run the validation, I still get below 75% coverege but there is no explanation. Does anyone know how to resolve this?
Thanks
Nitzan
Hi Nitzan,
Salesforce require mininum 75% code coverage of Apex code prior to PROD deployment. As you have added some new Apex code in your Apex Class you need to add test cases for that code.
You can go to Developer console -> Test Cases (bottom tab) and check for uncovered code.
Thanks,
Himanshu
All Answers
Hi Nitzan,
Salesforce require mininum 75% code coverage of Apex code prior to PROD deployment. As you have added some new Apex code in your Apex Class you need to add test cases for that code.
You can go to Developer console -> Test Cases (bottom tab) and check for uncovered code.
Thanks,
Himanshu
I "Run all tests" and got quite a few error messages:
All the ones I opened up are 'hidden' so I'm not sure how to proceed.
Thanks for your help.
Nitzan
Sorry, I'm still finding my way around this so will ask some basic questions...:-)
I think the screenshot I shared shows 71%. Am I looking in the right place?
your code should not be in red mark area once you check that class.
I ran the test for one of my classess and saw this list:
Does this mean that I need to focus on the classes with the lowest coverage percentage?
Thanks
I haven't touched ProjectTrigger so I don't understand why I need to make any changes to it. And I have no clue what I need to change :-(
Thanks for helping me with this and sticking with me, I appreciate it.
I still don't know which one is your deploy class. so here what I am proposing to resolve your issue.
Your main task is now to increase the code coverage and make it 75%,
If you don't have any idea about this trigger you can leave that but in that case you need to pick any other class or trigger where code coverage is very low. so for example if you have a class with 10% code coverage and you write test class for that and make it 70% your overall code coverage will go up, it can cross the 75% what we want to achieve so simply give it a try and let me know your progress ;)
If you face any issue while writing the class you can take help from here.
Thanks,
Himanshu
Thank you so much! With every answer I understand a bit more (I think....).
So, let me be more clear (and sorry I wasn't before. I wasn't sure what information you'd need).
The only (non test) class I changed is this:
public with sharing class TestUtilities {
public Contact aContac {get; set;}
public Attachment aAttachment {get; set;}
static User testUser;
public void generateContact(){
this.aContac = new Contact();
this.aContac.firstName = 'Test';
this.aContac.LastName = 'Test';
insert this.aContac;
this.aAttachment = new Attachment();
this.aAttachment.Body = Blob.valueOf('String');
}
public static TestUtilities generateTest(){
TestUtilities e = new TestUtilities();
e.generateContact();
return e;
}
public static User createUser(Id profileId)
{
//fetch existing users with provided profile and role
List<User> userLst = [Select Id From User where ProfileId =: profileId and IsActive = :true Limit 1];
User user;
if(userLst.size()>0)
{
//at least one user exists; return user record
user = userLst[0];
}
else
{
//user does not exist; create new user
user = new User(profileid = profileId,
alias = 'standt', email = 'standarduser@testorg.com',
emailencodingkey = 'UTF-8', lastname = 'Tsting', languagelocalekey = 'en_US',
localesidkey = 'en_US', timezonesidkey = 'America/Los_Angeles',
username = profileId + '@testorg.com');
insert user;
}
return user;
}
public static Clients__c insertClient()
{
Clients__c c = new Clients__c(Name ='TestClient', Active__c = true,
OC_Programme__c = 'OC Central', Current_Address__c = 'N/A',
Primary_Phone_Number__c = 'N/A');
return c;
}
public static Contact insertContact()
{
Contact c = new Contact(FirstName ='Test',LastName ='Test', Training_Contact__c = true);
return c;
}
public static Project__c insertProject()
{
Profile p = [select id from profile where name='OC Impact'];
UserRole r = [select id from UserRole where name='OC Impact Director'];
User userSRO = TestUtilities.createUser(p.Id);
RecordType rt = [select id from RecordType where SobjectType = 'Project__c' and DeveloperName = 'Project' limit 1];
string rId = rt.Id;
Project__c proj = new Project__c(Name = 'testProject',
OC_field__c = 'OC Impact',
Project_summary__c = 'Test Summary',
Project_start_date__c = date.newInstance(2013, 1, 1),
Project_end_date__c = date.newInstance(2013, 12, 25),
RecordtypeId = rt.id,
Submit_for_Approval_by__c = date.newInstance(2018, 12, 25),
Senior_Responsible_Officer_SRO__c = userSRO.Id);
return proj;
}
public static Project_Budget__c createProjectBudget(Id projId)
{
Project_Budget__c pb = new Project_Budget__c(Name = 'Session',
Cost_Centre__c = 'Session',
Income__c = 0,
Expense__c = 0,
Project__c = projId);
return pb;
}
public static Project_Budget_Detail__c createProjectBudgetDetail(Id projBudgetId)
{
Project_Budget_Detail__c pb = new Project_Budget_Detail__c(
Paid_As__c = 'Cash',
Income__c = 0,
Expense__c = 0,
Project_Budget__c = projBudgetId);
return pb;
}
}
I also changed 2 test clases:
1.
/**
*/
@isTest
private class AttendeeControllerTEST {
static testMethod void testAddClientToSession() {
Clients__c c = TestUtilities.insertClient();
insert c;
Project__c p = TestUtilities.insertProject();
insert p;
Event e = new Event(Subject='Test',ActivityDateTime=datetime.now(),WhatId=p.Id,DurationInMinutes=10);
insert e;
Test.setCurrentPageReference(Page.EventAttendees);
AttendeeController con = new AttendeeController();
apexPages.currentPage().getParameters().put('EventID', e.Id);
system.assert(con.ClientList.size()==1);
con.clientList[0].isSelected = true;
con.SaveAttendees();
}
static testMethod void testAddClientToAllSessions() {
Clients__c c = TestUtilities.insertClient();
insert c;
Project__c p = TestUtilities.insertProject();
insert p;
Event e = new Event(Subject='Test',ActivityDateTime=datetime.now(),WhatId=p.Id,DurationInMinutes=10);
insert e;
Test.setCurrentPageReference(Page.EventAttendees);
AttendeeController con = new AttendeeController();
apexPages.currentPage().getParameters().put('ProjectId', p.Id);
system.assert(con.ClientList.size()==1);
con.clientList[0].isSelected = true;
con.SaveAttendees();
}
}
2.
@isTest
private class TESTCLASS_EventTrigger {
static testMethod void validateEventTrigger() {
string mySubject = 'Test Class Call';
datetime myDateTime = datetime.newInstance(2012, 1, 1);
integer myDuration = 30;
Clients__c c = TestUtilities.insertClient();
insert c;
Event e = new Event(Subject=mySubject, WhatID = c.id,
DurationInMinutes=myDuration, StartDateTime=myDateTime);
insert e;
// Retrieve the new Event
e = [SELECT ID, Calendar_Title__c FROM Event WHERE Subject = :mySubject];
System.debug('Calendar_Title__c: ' + e.Calendar_Title__c);
// Test that the trigger correctly updated the price
System.assertEquals(c.Name + ': ' + mySubject, e.Calendar_Title__c);
}
}
I think the problem is here: TestUtilities as it only has 8% coverage:
But I wouldn't have a clue on where to start to increase coverage. It may be something simple that you can help me change. I hope so, anyway :-)
Again, thank you very much.
Take care