+ Start a Discussion
Dee Dee AaronDee Dee Aaron 

Code Coverage Failure Error

Hi there,
I am getting a code coverage failure warning. I'm not a developer, so I don't know where I went wrong? Thank you for your help.

1. I created an Apex Trigger and Apex Test Class
2. I attempted to deploy the change set and received:

Error: Code Coverage Failure
Your organization's code coverage is 0%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.

Apex Trigger
trigger FeedCommentUpdatetoNetPlanning on FeedComment (after insert) 
    Id profileId = UserInfo.getProfileId();
    String profileName =[Select Id, Name from Profile where Id=:profileId].Name;
    Set<id> SalesEngineeringSet = new Set<Id>();
    for(FeedComment f : Trigger.New)
        if(profileName  == 'GeoLinks Net Planning')
            if(ser.Status__c != 'Approved' && ser.Status__c != 'Unable to Meet Request'){
                ser.Status__c = 'Awaiting Reply from Rep';
        update serList;

Test Class
public class FeedCommentUpdatetoNetPlanning {
    public static void testFeedCommentUpdatetoNetPlanning() {
        //Create a User with Profile 'Net Planning Department'
        Id pid = [Select Id FROM Profile WHERE Name = 'Net Planning Department'].Id;
        User u = new User();
        u.ProfileId = pid;
        //here fill all the required fields for the User Record
        insert u;
        s.Status__c = //any Value othe than "Approved" and "Unable to Meet Request"
        //here fill all the required fields for the SALES_ENGINEERING_REQUEST__c Record
        s.Name = 'Test SER 1';
        s.Layer__c = 'Layer 2';
        //Since test class runs in the current user mode and in this Trigger lines will be covered only when the    //User has a Profile - 'Net Planning Department' hence we need trigger this event as the new User created with this //Profile
        System.runAs(u) {
            FeedComment f = new FeedComment();
            //here fill all the required fields for FeedCommentRecord
            insert f;
Best Answer chosen by Dee Dee Aaron
Andrew GAndrew G
I notice that your trigger references Profile Name 'GeoLinks Net Planning'
but your test data in the test class references  'Net Planning Department'

however, the feed comment insert should still give some coverage before the trigger stops at the test for the profile name.

When you run the test class in the Sandbox, what is the coverage for the trigger in the sandbox?