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
uHaveOptionsuHaveOptions 

Help on TestClass

I have this APEX Class but it's not passing.  Can you tell me why?

public class PQ_Update {
    public static void PQ_Update(List<ProdQueue__c> pq){ 
         List<Listing__c> ls= new list<Listing__c>();
        for(ProdQueue__c i : pq){
            ls.add(i.Listing__r);
            for (Listing__c l : ls){
                l.Production_Status__c=i.Status__c;
                l.OM_Approve__c=i.OM_Approve__c;
                l.Producer__c=i.Producer__c;
                update l;
            }
        }
        
    }
}



APEX @test

@isTest
public class PQ_UpdateTEST {
    public static testMethod void PQ_Update(){
        Listing__c l=new Listing__c();
        insert l;
        ProdQueue__c pq=new ProdQueue__c(Listing__c=l.id,Status__c='On-Market',OM_Approve__c='Yes',Producer__c='Brian');
    insert pq;
  
    }
}
venkat-Dvenkat-D
You need to invoke the method as well to pass the test. pass list of ProdQueue object to the method and it should pass.
uHaveOptionsuHaveOptions
It passes but says no code coverage... 0%
venkat-Dvenkat-D
In your test class, you should add

List<ProdQueue__c> newlist = new List<ProdQueue__c>();
newlist.add(pq);
PQ_Update.PQ_Update(newlist);
 
Mahesh DMahesh D
Hi Jon,

Please find the code below:

Class:

// Here I changed the method name just to make sure that its name is diff from Class Name.
public class PQ_Update {
    public static void PQ_UpdateOne(List<ProdQueue__c> pq){ 
         List<Listing__c> ls= new list<Listing__c>();
        for(ProdQueue__c i : pq){
            ls.add(i.Listing__r);
            for (Listing__c l : ls){
                l.Production_Status__c=i.Status__c;
                l.OM_Approve__c=i.OM_Approve__c;
                l.Producer__c=i.Producer__c;
                update l;
            }
        }        
    }
}

Test Class:
 
@isTest
public class PQ_UpdateTEST {
    public static testMethod void PQ_Update(){
        Listing__c l=new Listing__c();
        insert l;
        List<ProdQueue__c> pqList = new List<ProdQueue__c>();
		
		ProdQueue__c pqOne = new ProdQueue__c(Listing__c=l.id,Status__c='On-Market',OM_Approve__c='Yes',Producer__c='Brian One');
		ProdQueue__c pqTwo = new ProdQueue__c(Listing__c=l.id,Status__c='On-Market',OM_Approve__c='Yes',Producer__c='Brian Two');
		
		pqList.add(pqOne);
		pqList.add(pqTwo);
		
		insert pqList;
		
		PQ_Update.PQ_UpdateOne(pqList);
    }
}

Please do let me know if it helps you.

Regards,
Mahesh
uHaveOptionsuHaveOptions

PQ_Update.PQ_UpdateOne(pqList);   <- this is giving an error

Method does not exist or incorrect signature: PQ_Update.PQ_UpdateOne(List<ProdQueue__c>)

 

Still no code coverage

Mahesh DMahesh D
Hi Jon,

Please take my class and replace it with your class as I changed the method name.

Regards,
Mahesh
uHaveOptionsuHaveOptions

code coverage 6/9 66%

User-added image

error is in here.
PQ_Update.PQ_UpdateOne(pqList);   <- this is giving an error
Method does not exist or incorrect signature: PQ_Update.PQ_UpdateOne(List<ProdQueue__c>)

Mahesh DMahesh D
Hi Jon,

Please paste your class and test class here.

What I am saying is I changed the method name, please copy my class and my test class.

I changed both Apex Class and Test Class.

Regards,
Mahesh
uHaveOptionsuHaveOptions
public class PQ_Update {
    public static void PQ_UpdateOne(List<ProdQueue__c> pq){ 
         List<Listing__c> ls= new list<Listing__c>();
        for(ProdQueue__c i : pq){
            ls.add(i.Listing__r);
            for (Listing__c l : ls){
                l.Production_Status__c=i.Status__c;
                l.OM_Approve__c=i.OM_Approve__c;
                l.Producer__c=i.Producer__c;
                update l;
            }
        }        
    }
}
 
@isTest
public class PQ_UpdateTEST {
    public static testMethod void PQ_Update(){
        Listing__c l=new Listing__c();
        insert l;
        List<ProdQueue__c> pqList = new List<ProdQueue__c>();
		
		ProdQueue__c pqOne = new ProdQueue__c(Listing__c=l.id,Status__c='On-Market',OM_Approve__c='Yes',Producer__c='Brian One');
		ProdQueue__c pqTwo = new ProdQueue__c(Listing__c=l.id,Status__c='On-Market',OM_Approve__c='Yes',Producer__c='Brian Two');
		
		pqList.add(pqOne);
		pqList.add(pqTwo);
		
		insert pqList;
		
		PQ_Update.PQ_UpdateOne(pqList);
    }
}

I copied what you gave me.
Mahesh DMahesh D
Can you paste the Test Class Error message by taking the screen shot please.
uHaveOptionsuHaveOptions
User-added image
uHaveOptionsuHaveOptions
PQ_Update.PQ_UpdateOne(pqList);   <- this is giving an error
Method does not exist or incorrect signature: PQ_Update.PQ_UpdateOne(List<ProdQueue__c>)
Mahesh DMahesh D
public class PQ_Update {
    public static void PQ_Update(List<ProdQueue__c> pq){ 
         List<Listing__c> ls= new list<Listing__c>();
        for(ProdQueue__c i : pq){
            ls.add(i.Listing__r);
            for (Listing__c l : ls){
                l.Production_Status__c=i.Status__c;
                l.OM_Approve__c=i.OM_Approve__c;
                l.Producer__c=i.Producer__c;
                update l;
            }
        }        
    }
}
@isTest
public class PQ_UpdateTEST {
    public static testMethod void PQ_Update(){
        Listing__c l=new Listing__c();
        insert l;
        List<ProdQueue__c> pqList = new List<ProdQueue__c>();
		
		ProdQueue__c pqOne = new ProdQueue__c(Listing__c=l.id,Status__c='On-Market',OM_Approve__c='Yes',Producer__c='Brian One');
		ProdQueue__c pqTwo = new ProdQueue__c(Listing__c=l.id,Status__c='On-Market',OM_Approve__c='Yes',Producer__c='Brian Two');
		
		pqList.add(pqOne);
		pqList.add(pqTwo);
		
		insert pqList;
		
		PQ_Update.PQ_Update(pqList);
    }
}

Please take the above code and test it again.

--> Save the clas.
--> Save the Test Class
--> Run the Test Class

Let me know if you get any error in any step.

Regards,
Mahesh
 
uHaveOptionsuHaveOptions
I'm getting this test class error
Error: Compile Error: Method does not exist or incorrect signature: PQ_Update.PQ_Update(List<ProdQueue__c>) at line 16 column 9
uHaveOptionsuHaveOptions
That error...

Error: Compile Error: Method does not exist or incorrect signature: PQ_Update.PQ_Update(List<ProdQueue__c>) at line 16 column 9

before saving test class.
Mahesh DMahesh D
Hi Jon,

I simulated the whole process in my DE environment and everything is working fine properly.

Are you going to Setup --> Apex Class --> New   and then copying the class?

If not, can you do this way.

Don't use the Developer Console for now.

Regards,
Mahesh