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
Kris HankinsKris Hankins 

Testing customController for junction objects

I have some external objects in our org that I need to create a custom controller for. We have the Controller written, at least I believe it will work for what we need. My problem now is how do I test this controller in the sandbox since Lightning Connect is not enabled in our sandbox, only in production??

the controller code is below
 
public class NDSRentalContractController {
   Private final Account acct;
   public list<ER_HEADER__x> listContract   {get; set;}
   
   public NDSRentalContractController(ApexPages.StandardController stdController){
    this.acct = (Account) stdController.getRecord();
    listContract = [SELECT ExternalID, RH_OPEN_DATE__c from ER_HEADER__x WHERE RH1_CUSTOMER__c=:acct.NDS_Customer_Number__c];
   }    
}

 
Neetu_BansalNeetu_Bansal
Hi Kris,

So you need test class for this controller? If yes, use the below code:
@isTest
private class NDSRentalContractControllerTest
{
	static testMethod void myTest()
	{
		Test.startTest();
			Account nAcc = new Account( Name='Test Well Opp' );
			insert nAcc;
			
			ApexPages.StandardController sc = new ApexPages.standardController( nAcc );
	        
	        // Create instance of controller and call the methods
	        NDSRentalContractController controller = new NDSRentalContractController( sc );
		Test.stopTest();
	}
}
Let me know if you need any other help.

Thanks,
Neetu