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
Dee Dee AaronDee Dee Aaron 

Code Coverage Failure - Your code coverage is 0%.

Hi. I found this apex class online. It triggered successfully in my sandbox. When deploying to my production org, I tried validating and received an error: 
Code Coverage Failure: Your code coverage is 0%. 

This is the Apex Class:

public class DeleteUnacceptedQuotes 
{
@InvocableMethod    
public static void QuoteDelete(List<Id> OpportunityIds)    
{        
List<Quote> Quotes =[select id from quote                          
where Opportunity.id in :OpportunityIds                       
and Status != 'Accepted'];        
delete Quotes;   
}
}

Thank you for your help!
Best Answer chosen by Dee Dee Aaron
ANUTEJANUTEJ (Salesforce Developers) 
Hi Dee,

I was able to use the below code and I was able to achieve complete code coverage can your try checking this:
 
@isTest
public class DeleteUnacceptedQuotesT {
    private static testMethod void doTest() {
        list<id> olistid= new list<id>();
        
        Opportunity o= new Opportunity();
        o.Name='Test';
        o.StageName =  'Closed Won';
        o.CloseDate = system.today();
        insert o;
        olistid.add(o.id);
        
        Quote q= new Quote();
        q.name='TP';
        q.status='Denied';
        q.OpportunityId=o.id;
        insert q;
        
        Opportunity p= new Opportunity();
        p.Name='Test12';
        p.StageName =  'Closed Won';
        p.CloseDate = system.today();
        insert p;
        olistid.add(p.id);
                           
        Quote r= new Quote();
        r.name='TP';
        r.status='Denied';
        r.OpportunityId=p.id;
        insert r;
        
        DeleteUnacceptedQuotes.QuoteDelete(olistid);
        list<quote> ql= [select id from quote                          
                             where OpportunityId in :olistid                       
                             and Status != 'Accepted'];
        System.assertEquals(ql.size(), 0 , 'check the date inserted');
    }
    
}
For further understanding of trailhead module you can try checking the trailhead module https://trailhead.salesforce.com/en/content/learn/modules/apex_testing

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
 

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Dee,

I was able to use the below code and I was able to achieve complete code coverage can your try checking this:
 
@isTest
public class DeleteUnacceptedQuotesT {
    private static testMethod void doTest() {
        list<id> olistid= new list<id>();
        
        Opportunity o= new Opportunity();
        o.Name='Test';
        o.StageName =  'Closed Won';
        o.CloseDate = system.today();
        insert o;
        olistid.add(o.id);
        
        Quote q= new Quote();
        q.name='TP';
        q.status='Denied';
        q.OpportunityId=o.id;
        insert q;
        
        Opportunity p= new Opportunity();
        p.Name='Test12';
        p.StageName =  'Closed Won';
        p.CloseDate = system.today();
        insert p;
        olistid.add(p.id);
                           
        Quote r= new Quote();
        r.name='TP';
        r.status='Denied';
        r.OpportunityId=p.id;
        insert r;
        
        DeleteUnacceptedQuotes.QuoteDelete(olistid);
        list<quote> ql= [select id from quote                          
                             where OpportunityId in :olistid                       
                             and Status != 'Accepted'];
        System.assertEquals(ql.size(), 0 , 'check the date inserted');
    }
    
}
For further understanding of trailhead module you can try checking the trailhead module https://trailhead.salesforce.com/en/content/learn/modules/apex_testing

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
 
This was selected as the best answer
Dee Dee AaronDee Dee Aaron
Hi Anutej. Thank you for answering my question. I am marking as best answer-- even though I ended up using a process builder and a flow to accomplish this. I'm sharing here for other users that might be looking to do the same thing: https://trailblazers.salesforce.com/answers?id=9064S000000DKhwQAG