+ Start a Discussion
ANDRI nomenaANDRI nomena 

test class remont action

some one can help me how to test this method
My Controller Code:
... @RemoteAction
    public static List<JSStove> getStoves(Id ResellerID) {// include Id ResellerID from VF
        
        List<JSStove> stoves = new List<JSStove>();
        for (Product_item__c stove : [SELECT Id, Name FROM Product_item__c
                                      WHERE Reseller__c =:ResellerID ORDER BY Name ASC]) {                      
                                      
            stoves.add(new JSStove(stove.Name, stove.Id));
        }
        return stoves;
    }

Please help me.
Thanks in Advance
Best Answer chosen by ANDRI nomena
Raj VakatiRaj Vakati
Use this code
 
@isTest
public class MyControllerTest {
    
    @isTest
    public void getStovesTest(){
        //Create a Reseller__c  record
		Reseller__c rs = new Reseller__c();
		rs.name = 'TestData';
		insert rs;
		
        //Create a Product_item__c  record
        //give the necessary details
        Product_item__c pi = new Product_item__c();
        pi.name = 'TestPrd';
		pi.Reseller__c  = rs.id;
		insert pi;
		
	    Product_item__c pi1 = new Product_item__c();
        pi1.name = 'TestPrd1';
		pi1.Reseller__c  = rs.id;
		insert pi1;
		
        
        //give the resellerId of the record you created above
        MyControllerTest.getStoves(pi1.Id);
    }
}

 

All Answers

Mohan ChanderMohan Chander
Hi Andri,

I have gave very basic code to cover your method.
Hope this helps.

@isTest
public class MyControllerTest {
    
    @isTest
    public void getStovesTest(){
        
        //Create a Product_item__c  record
        //give the necessary details
        Product_item__c testRecord = new Product_item__c();
        
        //give the resellerId of the record you created above
        MyControllerTest.getStoves(resellerId);
    }
}

Regards,
Mohan
 
v varaprasadv varaprasad
Hi Andri,

Please check once below sample code:
 
@isTest
public class MyControllerTest {
    
    @isTest
    public void getStovesTest(){
        //Create a Reseller__c  record
		Reseller__c rs = new Reseller__c();
		rs.name = 'TestData';
		insert rs;
		
        //Create a Product_item__c  record
        //give the necessary details
        Product_item__c pi = new Product_item__c();
        pi.name = 'TestPrd';
		pi.Reseller__c  = rs.id;
		insert pi;
		
	    Product_item__c pi1 = new Product_item__c();
        pi1.name = 'TestPrd1';
		pi1.Reseller__c  = rs.id;
		insert pi1;
		
		List<JSStove> stoves = new List<JSStove>();
		
        //give the resellerId of the record you created above
        stoves = MyControllerTest.getStoves(rs.id);
    }
}

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.


Salesforce Freelance Consultant/Developer/Administrator/Trainer
@For Salesforce Project Support: varaprasad4sfdc@gmail.com


Salesforce latest interview questions and training videos :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1

 
ANDRI nomenaANDRI nomena
Hi varaprasad,
it work but at the end it have error
Compile Error: Invalid type: JSStove
can you explain
Regards,
Andri
Raj VakatiRaj Vakati
Use this code
 
@isTest
public class MyControllerTest {
    
    @isTest
    public void getStovesTest(){
        //Create a Reseller__c  record
		Reseller__c rs = new Reseller__c();
		rs.name = 'TestData';
		insert rs;
		
        //Create a Product_item__c  record
        //give the necessary details
        Product_item__c pi = new Product_item__c();
        pi.name = 'TestPrd';
		pi.Reseller__c  = rs.id;
		insert pi;
		
	    Product_item__c pi1 = new Product_item__c();
        pi1.name = 'TestPrd1';
		pi1.Reseller__c  = rs.id;
		insert pi1;
		
        
        //give the resellerId of the record you created above
        MyControllerTest.getStoves(pi1.Id);
    }
}

 
This was selected as the best answer