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
ekarthikekarthik 

Test method for get set

Hi

 

    I am doing test method. I am struck with 65%. I am in need of help for the following

 

public string splashRun{
get{
Date dateValid = date.today();
Date todayDate = date.newInstance(dateValid.year(),dateValid.month(),dateValid.day());
string UserId = Userinfo.getUserId();
User userLogin = [select LastLoginDate from User where Id = :UserId];
DateTime lastLogin = userLogin.LastLoginDate;
Date loginDate = date.newInstance(lastLogin.year(),lastLogin.month(),lastLogin.day());

if(loginDate == todayDate){

splash = [select Name, Flag__c, Visit_Date__c from Splash_Data__c where Name = :Userinfo.getUserId()];
if(splash[0].Flag__c == 0){
splashRun = 'true';
}
else if(splash[0].Flag__c == 1){
splashRun = 'true';
}
else if(splash[0].Flag__c == 2){
splashRun = 'false';
}



}
return splashRun;
}
set;
}

 

 

 

How to accomplish test method for the above.. I write like this in multiple areas

 

Best Answer chosen by Admin (Salesforce Developers) 
imutsavimutsav
Suppose your actual class name is Emp.

now in your test class write
Emp e = new Emp();
e.splashRun = 'My Test';
String x = e.splashRun;
I suppose this should work.

or else
Emp e = new Emp();
e.setSplashRun('My Test');
String x = e.getSplashRun();


Thanks
Utsav


[Do mark this answer as solution if it works for you and give a kudos.]

All Answers

imutsavimutsav
Suppose your actual class name is Emp.

now in your test class write
Emp e = new Emp();
e.splashRun = 'My Test';
String x = e.splashRun;
I suppose this should work.

or else
Emp e = new Emp();
e.setSplashRun('My Test');
String x = e.getSplashRun();


Thanks
Utsav


[Do mark this answer as solution if it works for you and give a kudos.]
This was selected as the best answer
ramsreeramsree

how to testing tigger method

imutsavimutsav
Try this.

http://teachmesalesforce.wordpress.com/2011/05/07/how-to-write-a-trigger-test/

and if you have any specific code then share the code.

Thanks
Utsav

[Do mark this answer as solution if it works for you and give a kudos.]