You need to sign in to do that
Don't have an account?
Walid Safieh 17
Code Coverage 0% Even though Sandbox is at 100 % Coverage
Hi Everyone,
I'm having an issue with code coverage when I'm attempting to import a change set into production. For some reason no matter what I do, my coverage is always at 0% and gives me a fatal error even though my sandbox is showing 100 percent. Here is my code below! Any help would be appreciated.
Public class AutoConvertLead
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
for(id currentlead: LeadIds){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead);
Leadconvert.setOwnerId(Userinfo.getUserId());
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
MassLeadconvert.add(Leadconvert);
}
List<ID> LeadAccounts = new List<ID>();
List<ID> LeadOpportunities = new List<ID>();
if (!MassLeadconvert.isEmpty()) {
for(Database.leadconvert acc : MassLeadConvert){
Database.LeadConvertResult art = database.convertlead(acc);
LeadAccounts.add(art.getAccountId());
LeadOpportunities.add(art.getOpportunityId());
}
List<Account> LeadAccountsupdate = [Select ID, name, npe01__One2OneContact__c,(Select FirstName, Lastname, AccountId, ID from Contacts Limit 1) From Account Where ID in :LeadAccounts];
System.debug(LeadAccountsupdate.size());
for(Account acc: LeadAccountsupdate){
System.debug(acc.contacts[0]);
acc.name = acc.contacts[0].firstname + ' ' + acc.contacts[0].lastname + ' Household';
acc.npe01__One2OneContact__c = acc.contacts[0].id;
update acc;
}
List<Opportunity> LeadOpportunitiesupdate = [Select ID, Name, npsp__Primary_Contact__c, Pick_up__c, Type_of_Good__c, Closedate, account.npe01__One2OneContact__r.name From Opportunity Where ID in :LeadOpportunities];
for(Opportunity opp: LeadOpportunitiesupdate){
String[] multi = opp.Type_of_Good__c.split(';');
String rcc = string.valueof(opp.CloseDate);
opp.name = opp.account.npe01__One2OneContact__r.name + ' / ' + opp.Pick_up__c + ' / ' + multi + ' / ' + rcc;
opp.npsp__Primary_Contact__c = opp.account.npe01__One2OneContact__c;
update opp;
}
}
}
}
Here below is my test class
@isTest
public class AutoConvertLeadTest {
static testMethod void validateAutoConvertLead() {
Test.startTest();
Lead testLead = new lead();
testLead.firstname = 'qasx';
testLead.LastName = 'Bucker';
testLead.Company = 'Not Applicable';
testLead.LeadSource = 'Web';
testLead.Pick_up_or_Drop_off__c = 'Pick Up';
testLead.Type_of_Good__c = 'Meat';
testLead.OwnerId = Userinfo.getUserId();
testLead.Status = 'Convert Automation';
insert testLead;
test.stopTest();
}
}
I'm having an issue with code coverage when I'm attempting to import a change set into production. For some reason no matter what I do, my coverage is always at 0% and gives me a fatal error even though my sandbox is showing 100 percent. Here is my code below! Any help would be appreciated.
Public class AutoConvertLead
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
for(id currentlead: LeadIds){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId(currentlead);
Leadconvert.setOwnerId(Userinfo.getUserId());
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
MassLeadconvert.add(Leadconvert);
}
List<ID> LeadAccounts = new List<ID>();
List<ID> LeadOpportunities = new List<ID>();
if (!MassLeadconvert.isEmpty()) {
for(Database.leadconvert acc : MassLeadConvert){
Database.LeadConvertResult art = database.convertlead(acc);
LeadAccounts.add(art.getAccountId());
LeadOpportunities.add(art.getOpportunityId());
}
List<Account> LeadAccountsupdate = [Select ID, name, npe01__One2OneContact__c,(Select FirstName, Lastname, AccountId, ID from Contacts Limit 1) From Account Where ID in :LeadAccounts];
System.debug(LeadAccountsupdate.size());
for(Account acc: LeadAccountsupdate){
System.debug(acc.contacts[0]);
acc.name = acc.contacts[0].firstname + ' ' + acc.contacts[0].lastname + ' Household';
acc.npe01__One2OneContact__c = acc.contacts[0].id;
update acc;
}
List<Opportunity> LeadOpportunitiesupdate = [Select ID, Name, npsp__Primary_Contact__c, Pick_up__c, Type_of_Good__c, Closedate, account.npe01__One2OneContact__r.name From Opportunity Where ID in :LeadOpportunities];
for(Opportunity opp: LeadOpportunitiesupdate){
String[] multi = opp.Type_of_Good__c.split(';');
String rcc = string.valueof(opp.CloseDate);
opp.name = opp.account.npe01__One2OneContact__r.name + ' / ' + opp.Pick_up__c + ' / ' + multi + ' / ' + rcc;
opp.npsp__Primary_Contact__c = opp.account.npe01__One2OneContact__c;
update opp;
}
}
}
}
Here below is my test class
@isTest
public class AutoConvertLeadTest {
static testMethod void validateAutoConvertLead() {
Test.startTest();
Lead testLead = new lead();
testLead.firstname = 'qasx';
testLead.LastName = 'Bucker';
testLead.Company = 'Not Applicable';
testLead.LeadSource = 'Web';
testLead.Pick_up_or_Drop_off__c = 'Pick Up';
testLead.Type_of_Good__c = 'Meat';
testLead.OwnerId = Userinfo.getUserId();
testLead.Status = 'Convert Automation';
insert testLead;
test.stopTest();
}
}
I would suggest calling your invocable method inside your test class. Might be Process builder is having some issue in deployment and not able to call your Invocable method.
Modified your test class code as:
Please try this let me know if it works.
Thanks and Regards
Ayush Sharma
All Answers
Not sure if you missed to include your test class during deployment validation.
Please re-check and include class and test class while you validate against production.
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Vinay Kumar
Thank you for your reply. I have tried it in every way, including the test class with my process builder flow and all dependencies. After that didn't work I attempted to just send over the test class and apex class invocable method. In both ways, the same error came back notifying me I have 0 percent code coverage. Any ideas?
Thanks!
I would suggest calling your invocable method inside your test class. Might be Process builder is having some issue in deployment and not able to call your Invocable method.
Modified your test class code as:
Please try this let me know if it works.
Thanks and Regards
Ayush Sharma
I believe that since Process Builder are always deployed Inactive, when doing the validation they are still inactive so we need to manually call the invocable method.