Why when I try to deploy my class is it saying that the code coverage is 0%. I don't understand what I need to do for the class to pass? I set up a change set with the two classes below, and when i click validate > run specific tests > "TEST_OpOwnerConvertedServiceNotif" it says the code coverage is 0%.
I have clicked "Run Test" within the test class and it passes, what more do I need to do?
When I'm in the developer console in the class, it also says that code coverage is "None"
Below is my test class:
@istest private class TEST_OpOwnerConvertedServiceNotif
{
static testMethod void TEST_OpOwnerConvertedServiceNotif ()
{
Account acc = new Account(Name = 'Test Account');
insert acc;
ID pricebookId = Test.getStandardPricebookId();
Product2 prd1 = new Product2(
Name = 'Test Product Entry 1',
Description = 'Test Product Entry 1',
productCode = 'ABC', isActive = false,
RecordTypeId = '0128E0000004m8b',
R_D_Service_Owner__c = '005w0000004x3RiAAI',
Convert_to_Service_Catalogue_Initiated__c = TRUE,
Convert_to_Service_Catalogue_Emailed__c = FALSE
);
insert prd1;
PricebookEntry pbe1 = new PricebookEntry(
Product2ID=prd1.id,
Pricebook2ID = pricebookId,
UnitPrice=0,
isActive=true
);
insert pbe1;
Opportunity opp1 = new Opportunity(
Name='Opp1',
StageName='Proposal Accepted',
CloseDate=Date.today(),
Pricebook2Id = pbe1.Pricebook2Id,
AccountId = acc.id
);
insert opp1;
OpportunityLineItem lineItem1 = new OpportunityLineItem(
OpportunityID = opp1.id,
PriceBookEntryID = pbe1.id,
quantity=1,
totalprice=0
);
insert lineItem1;
Test.startTest();
Test.stopTest();
}
}
Below is the class related to the test:
global class OpOwnerConvertedServiceNotif Implements Schedulable
//If an R&D Service or project is converted to a full service record, when it is already attached to an opportunity, a notification will be sent to the opportunity owner, informing them of the change
{
global void execute (SchedulableContext sc)
{
sendConvertedEmailToOppOwner();
}
public void sendConvertedEmailToOppOwner()
{
List<Opportunity> listOpportunity = new List <Opportunity>();
listOpportunity = [
SELECT Id, OwnerId,Name,Owner.FirstName,
(SELECT Id, Product2.Name FROM OpportunityLineItems
WHERE Product2.Convert_to_Service_Catalogue_Emailed__c = FALSE
AND Product2.Convert_to_Service_Catalogue_Initiated__c = TRUE)
FROM Opportunity
WHERE StageName != 'Closed Won - Signed Contract' AND StageName != 'Closed Lost' AND Id in
(SELECT OpportunityId
FROM OpportunityLineItem
WHERE Product2.Convert_to_Service_Catalogue_Emailed__c = FALSE
AND Product2.Convert_to_Service_Catalogue_Initiated__c = TRUE)
];
for(Opportunity opp :listOpportunity)
{
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
{
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTargetObjectId(opp.OwnerId);
email.setReplyTo('[email protected]');
email.setSenderDisplayName('Salesforce Support');
for(opportunitylineitem oppLineItem:opp.opportunitylineitems)
email.setSubject('An R&D service or project attached to an opportunity owned by you has been progressed to a live service');
String body ='Hi ' + opp.Owner.FirstName + ',';
body += '<br><br>Salesforce recognises you as the owner of the following opportunity: ' + opp.Name;
for(opportunitylineitem oppLineItem:opp.opportunitylineitems)
body += '<br><br>Attached to this opportunity is an R&D service or project:'+oppLineItem.Product2.Name + '. This service or project has been progressed to a live service, so is no longer available.';
body += '<br><br>Please use the link below to update the opportunity';
body += '<br><br>test.salesforce.com/'+opp.id;
email.setHtmlBody(body);
email.setSaveAsActivity(false);
emails.add(email);
}
Messaging.sendEmail(emails);
update listOpportunity;
}
Map<Id,Product2> products = new Map<Id, Product2>();
for(Opportunity opp: listOpportunity){
for(OpportunityLineItem oppLineItem: opp.opportunitylineitems){
products.put(oppLineItem.Product2Id, new Product2(Id=oppLineItem.Product2Id, Convert_To_Service_Catalogue_Emailed__c = TRUE));
}
}
update products.values();
}
}
Test.startTest()andTest.stopTest()– RCS 4 hours agoglobalaccess modifier. Also every test method should contain assertions. – Adrian Larson 4 hours ago