function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jean-Se DoraisJean-Se Dorais 

Inbound Change Set - Code Coverage Error (69%)

Hello all,

I have 1 Apex Class in a change set.  Everything works in Sandbox env. but when I try to bring the Class into Prod via an inbound change set, I get: 

Code Coverage Failure
Your code coverage is 69%. You need at least 75% coverage to complete this deployment.


Here is my Apex Class
public class CurrentRecordIdController{
public String currentRecordId {get;set;}
public String parameterValue {get;set;}
public Lead lead{get;set;}

public String data {get;set;}
public Blob mac {get;set;}
public String sig {get;set;}
public String url {get;set;}
 
    public CurrentRecordIdController(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        lead = [Select Id, Name, Email, Company from Lead where Id =: currentRecordId ];
        parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');

        data = currentRecordId;
        mac = Crypto.generateMac('HMacSHA256', Blob.valueOf(data), Blob.valueOf('kay'));
        sig = EncodingUtil.urlEncode(EncodingUtil.base64Encode(mac), 'UTF-8');
        url = 'https://mysite.com/123456?lid=' + currentRecordId + '&signature=' + sig;

}

}

Any tips on how to get past this issue? I read somewhere that I need a test class in my code but I do not know how to do that.

Thank you!
Best Answer chosen by Jean-Se Dorais
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Jean,

You can write the new test class as below. Just replace the word samplelead with your lead visualforce page name from your org. This will give you 100% coverage
 
@isTest
private  class CurrentRecordIdControllerTest {
static testMethod void myUnitTest() 
    {
       Lead led = new Lead(Company = 'JohnMiller', LastName = 'Mike', Status = 'Open' );
        insert led;



PageReference pageRef = Page.samplelead;
Test.setCurrentPage(pageRef);
ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(led);
ApexPages.currentPage().getParameters().put('Id',led.id);

CurrentRecordIdController ec = new CurrentRecordIdController(sc);
    }
}

If this solution helps, Please mark it as best answer.

Thanks,


 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Jean,

Can you please share the visual force page associated to this apex class with the name of the page as well.

Thanks,
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Jean,

You can write the new test class as below. Just replace the word samplelead with your lead visualforce page name from your org. This will give you 100% coverage
 
@isTest
private  class CurrentRecordIdControllerTest {
static testMethod void myUnitTest() 
    {
       Lead led = new Lead(Company = 'JohnMiller', LastName = 'Mike', Status = 'Open' );
        insert led;



PageReference pageRef = Page.samplelead;
Test.setCurrentPage(pageRef);
ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(led);
ApexPages.currentPage().getParameters().put('Id',led.id);

CurrentRecordIdController ec = new CurrentRecordIdController(sc);
    }
}

If this solution helps, Please mark it as best answer.

Thanks,


 
This was selected as the best answer