• Nitish Pandey 14
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello,

I am facing issue in Trailhead : Queueable Apex
https://trailhead.salesforce.com/asynchronous_apex/async_apex_queueable

We have to write a class and test class for 100% code coverage.
But on Validating, I am getting error: 

Challenge Not yet complete... here's what's wrong: 
The 'AddPrimaryContactTest' test class doesn't appear to be using the 'AddPrimaryContact' class.


He are  my classes:
global class AddPrimaryContact implements Queueable {
    
    private Contact queueContact;
    private String contactState;
    
    public AddPrimaryContact(){}
    
    public AddPrimaryContact(Contact con, String state){
        queueContact = con;
        contactState = state;
    }
    
    public void execute(QueueableContext context){
        
        List<Account> accList = [select id,name from Account  where BillingState =: contactState limit 200];
        List<Contact>conList = new List<Contact>();
        for(account acl : accList){
            Contact cont = queueContact.clone(false);
            cont.AccountId=acl.id;
            conList.add(cont);
        }
        insert conList;
        
    }
}

Test class:
@isTest
public class AddPrimaryContactTest {
    
    @testSetup
    public static void setup(){
        
        List<Account> accList = new List<Account>();
        for(integer ing =0;ing<50; ing++){
            Account acc = new Account(Name='TEst Acc',BillingState ='NY');
            accList.add(acc);
        }    
        
        for(integer ing =0;ing<50; ing++){
            Account acc = new Account(Name='TEst Acc',BillingState ='CA');
            accList.add(acc);
        } 
        
        insert accList;
        
        Contact con = new Contact(LastName='TestContact');
        insert con;
    }
    
   static testmethod  void testAcount(){
        
        contact con = [select id,name,AccountId from contact where name='TestContact'];
         Test.startTest();
         
        AddPrimaryContact ad = new AddPrimaryContact ();
        AddPrimaryContact updater = new AddPrimaryContact (con, 'CA');
        // startTest/stopTest block to force async processes to run
               System.enqueueJob(ad);
        ID jobID = System.enqueueJob(updater);
        Test.stopTest();       
        
    }
}
I am getting 100% code coverage for my class.
Hello,

I am facing issue in Trailhead : Queueable Apex
https://trailhead.salesforce.com/asynchronous_apex/async_apex_queueable

We have to write a class and test class for 100% code coverage.
But on Validating, I am getting error: 

Challenge Not yet complete... here's what's wrong: 
The 'AddPrimaryContactTest' test class doesn't appear to be using the 'AddPrimaryContact' class.


He are  my classes:
global class AddPrimaryContact implements Queueable {
    
    private Contact queueContact;
    private String contactState;
    
    public AddPrimaryContact(){}
    
    public AddPrimaryContact(Contact con, String state){
        queueContact = con;
        contactState = state;
    }
    
    public void execute(QueueableContext context){
        
        List<Account> accList = [select id,name from Account  where BillingState =: contactState limit 200];
        List<Contact>conList = new List<Contact>();
        for(account acl : accList){
            Contact cont = queueContact.clone(false);
            cont.AccountId=acl.id;
            conList.add(cont);
        }
        insert conList;
        
    }
}

Test class:
@isTest
public class AddPrimaryContactTest {
    
    @testSetup
    public static void setup(){
        
        List<Account> accList = new List<Account>();
        for(integer ing =0;ing<50; ing++){
            Account acc = new Account(Name='TEst Acc',BillingState ='NY');
            accList.add(acc);
        }    
        
        for(integer ing =0;ing<50; ing++){
            Account acc = new Account(Name='TEst Acc',BillingState ='CA');
            accList.add(acc);
        } 
        
        insert accList;
        
        Contact con = new Contact(LastName='TestContact');
        insert con;
    }
    
   static testmethod  void testAcount(){
        
        contact con = [select id,name,AccountId from contact where name='TestContact'];
         Test.startTest();
         
        AddPrimaryContact ad = new AddPrimaryContact ();
        AddPrimaryContact updater = new AddPrimaryContact (con, 'CA');
        // startTest/stopTest block to force async processes to run
               System.enqueueJob(ad);
        ID jobID = System.enqueueJob(updater);
        Test.stopTest();       
        
    }
}
I am getting 100% code coverage for my class.