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
Sindhu1234Sindhu1234 

Invalid interface: Queueable

I'm on Trailahead challege ,while coding came accross an error says "Invalid interface: Queueable".
Tried using "small q as queueable" but it doesn't resolved.Any clue where i am going wrong
//Queueable Apex

public class AddPrimaryContact implements Queueable

{
	private Contact c;

    private String state;

    public  AddPrimaryContact(Contact c, String state)

    {

        this.c = c;

        this.state = state;

    }

    public void execute(QueueableContext context)

    {

         List<Account> ListAccount = [SELECT ID, Name ,(Select id,FirstName,LastName from contacts ) FROM ACCOUNT WHERE BillingState = :state LIMIT 200];

         List<Contact> lstContact = new List<Contact>();

         for (Account acc:ListAccount)

         {

                 Contact cont = c.clone(false,false,false,false);

                 cont.AccountId =  acc.id;

                 lstContact.add( cont );

         }

          

         if(lstContact.size() >0 )

         {

             insert lstContact;

         }

              

    }

 

}

 
Best Answer chosen by Sindhu1234
Sindhu1234Sindhu1234
Thank you @Amit. i found the reason. 
I have changed the Version and it got fxed.

All Answers

Amit Chaudhary 8Amit Chaudhary 8
 Please check in your org you have any class with Queueable Name ? If yes then please delete the class or rename

I tested below code in my org which is working fine
public class AddPrimaryContact implements Queueable
{
    private Contact c;
    private String state;
    public  AddPrimaryContact(Contact c, String state)
    {
        this.c = c;
        this.state = state;
    }
    public void execute(QueueableContext context) 
    {
         List<Account> ListAccount = [SELECT ID, Name ,(Select id,FirstName,LastName from contacts ) FROM ACCOUNT WHERE BillingState = :state LIMIT 200];
         List<Contact> lstContact = new List<Contact>();
         for (Account acc:ListAccount)
         {
                 Contact cont = c.clone(false,false,false,false);
                 cont.AccountId =  acc.id;
                 lstContact.add( cont );
         }
         
         if(lstContact.size() >0 )
         {
             insert lstContact;
         }
             
    }

}
Test class
@isTest
public class AddPrimaryContactTest 
{
     @isTest static void TestList()
     {
         List<Account> Teste = new List <Account>();
         for(Integer i=0;i<50;i++)
         {
             Teste.add(new Account(BillingState = 'CA', name = 'Test'+i));
         }
         for(Integer j=0;j<50;j++)
         {
             Teste.add(new Account(BillingState = 'NY', name = 'Test'+j));
         }
         insert Teste;

         Contact co = new Contact();
         co.FirstName='demo';
         co.LastName ='demo';
         insert co;
         String state = 'CA';
      
          AddPrimaryContact apc = new AddPrimaryContact(co, state);
          Test.startTest();
            System.enqueueJob(apc);
          Test.stopTest();
      }
 }


Let us know if this will help you

Thanks
Amit Chaudhary
 
Sindhu1234Sindhu1234
I have checked no other class with the same title. This is working in my test environment but not in the free developer edition
 
Sindhu1234Sindhu1234
Thank you @Amit. i found the reason. 
I have changed the Version and it got fxed.
This was selected as the best answer