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
SANDEEP CHITTINENISANDEEP CHITTINENI 

How can i write a test class for apex class-----Can I grab some help??

public class FieldUpdate {
    public List<Vehicle__c> v;
    public String st;
    
    public void FieldUpdate(){
        v=[select id,Date__c,Status__c from Vehicle__c where (Date__c=:date.today())];
        for(Vehicle__c vh : v)
        {
           if(vh.Date__c==date.today())
            {
                st=vh.Status__c;
                string lt=st.remove('-Future');
                vh.Status__c=lt;                
                update vh;               
            }
           
        }
    }
}



Thank you,
Sandeep
Best Answer chosen by SANDEEP CHITTINENI
sfdcMonkey.comsfdcMonkey.com
hi sandeep
try below test class it will give 100% code coverage
@isTest
public class TestClassSample {
	static testMethod void test() {
        List<Vehicle__c> vList = new List<Vehicle__c>();
       Vehicle__c v = new Vehicle__c();
        v.Name = 'bikeOne';
        v.Date__c = date.today();
        v.Status__c = 'test-Future';
        insert v;        
        vList.add(v);
        FieldUpdate fl = new FieldUpdate();
        fl.FieldUpdate();
        
        
    }
}
I hop it helps you
Mark it best answer if it helps you so it make proper solution for others
Thanks

 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi sandeep
try below test class it will give 100% code coverage
@isTest
public class TestClassSample {
	static testMethod void test() {
        List<Vehicle__c> vList = new List<Vehicle__c>();
       Vehicle__c v = new Vehicle__c();
        v.Name = 'bikeOne';
        v.Date__c = date.today();
        v.Status__c = 'test-Future';
        insert v;        
        vList.add(v);
        FieldUpdate fl = new FieldUpdate();
        fl.FieldUpdate();
        
        
    }
}
I hop it helps you
Mark it best answer if it helps you so it make proper solution for others
Thanks

 
This was selected as the best answer
SANDEEP CHITTINENISANDEEP CHITTINENI
Thank you very much.....piyush soni. It helped me so much. This is my first exersie. Thank you once again soni
sfdcMonkey.comsfdcMonkey.com
keep learning
go to below link for best practice of writing  test class
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html
Thanks :)