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
SFDC_TTLSFDC_TTL 

Setting controller parameters in test class

Hi,

 

fromLogo and ToLogo are two lookup fields to account from a custom object (Account_Movement__c)  in my VF page.

 

public with sharing class AccMvmtController

{

public AccMvmtController(ApexPages.standardController cont)

{

fromLogo=newAccount_Movement__c();

toLogo =newAccount_Movement__c();

isnotblank=

false;

 }

 

public Account_Movement__c fromLogo {get;set;}

 

publicAccount_Movement__c toLogo {get;set;}

 

}

 

@istest

privatestaticvoidtestAccMvmtController()

{

 

System.runas(semiAdmin) {

 

Test.StartTest();

 

PageReference pageref = Page.CompanyMovement;

Test.setCurrentPage(pageRef);

 

Test.StopTest();

 

}

 

How to set parameters for fromLogo and ToLogo in my test class

 

Please suggest.

 

Thanks

 

asish1989asish1989

Hi

 Create an instance of that class inside test class, It will automatically cover , If not then do one thing

Assign that varibale with some hardcoded value 

instance . variable = something which sholud be same type as variable ;

 

@istest

privatestaticvoidtestAccMvmtController()

{

 

System.runas(semiAdmin) {

 

Test.StartTest();

     AccMvmtController  clsInstance =  AccMvmtController();

 

PageReference pageref = Page.CompanyMovement;

 

 //optional ......You will try this If above trick does not work 

    Account_Movement__c  testActMov = new Account_Movement__c( );

       testActMov.someRequiredFied = 'something' ;

       insert  testActMov;

       clsInstance .fromLogo = testActMov ;

 

Test.setCurrentPage(pageRef);

 

Test.StopTest();

 

}

     

Let me know It works or not 

 

Did this post answers your Question,If so please mark it as Solved and hit kudos icon for this Post

 

   Thanks

 

Maros SitkoMaros Sitko

use this before Test.stoptest();

Account_Movement__c objO = new Account_Movement__c();
AccMvmtController TC = new V2SA_AccMvmtController(new ApexPages.StandardController(objO));
TC.fromLogo = new Account_Movement__c();
TC.toLogo = new Account_Movement__c();

 

Maros

SFDC_TTLSFDC_TTL
But how to set the values to fromLOGO and toLOGO
Bhawani SharmaBhawani Sharma
TC.fromLogo = new Account_Movement__c();
TC.toLogo = new Account_Movement__c();

There are the way to set the values, if you are talking about get:

Then do this 

 

Account_Movement__c aM1 = TC.fromLogo;
Account_Movement__c aM2= TC.toLogo();