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
Samadhan Sakhale 3Samadhan Sakhale 3 

Writing Test Class

Hi All,
     I am new to SFDC and i have written one trigger but i'm not able to write test class for it someone please tell me how can i write test class  for this trigger my Trigger is

trigger FetchVatvalue on Quote__c (before insert,before update) 
{
    //create reference table for lookup value
    Map<String, Decimal> vatMap = new Map<String, Decimal>();
    //build reference table for VAT rates
    for (VAT__c vat : [SELECT Name,Vat_Rate__c FROM VAT__c])
        vatMap.put(vat.Name, vat.Vat_Rate__c);
    //update Quote__c with VAT rate
    for (Quote__c q : trigger.new)
    {
        Decimal vatRate = vatMap.get(q.Country_Code__c);
        q.VAT_Rate__c = vatRate;
    }
}

this trigger is wrtten for automaticaly fetch value from another object using picklist

thank you,
Sam
Best Answer chosen by Samadhan Sakhale 3
Deepak Kumar ShyoranDeepak Kumar Shyoran
@isTest()
private class Test_Quote {

	static testMethod void uniTest() {
		test.startTest() ;
		VAT__c vat = new Vate__c(Name='Test Vate',Vat_Rate__c = 50 );
		insert vat ;
		Quote__c qu = new Quote__c(Name='Test Quote')
		insert qu ;
		test.stopTest() ;
	}	
}

Hope it'll help you.
 

All Answers

Deepak Kumar ShyoranDeepak Kumar Shyoran
@isTest()
private class Test_Quote {

	static testMethod void uniTest() {
		test.startTest() ;
		VAT__c vat = new Vate__c(Name='Test Vate',Vat_Rate__c = 50 );
		insert vat ;
		Quote__c qu = new Quote__c(Name='Test Quote')
		insert qu ;
		test.stopTest() ;
	}	
}

Hope it'll help you.
 
This was selected as the best answer
Samadhan Sakhale 3Samadhan Sakhale 3
hi deepak,
   is there compulsory to write assertEqual() function in test class

Sam
Deepak Kumar ShyoranDeepak Kumar Shyoran
Normally they are not . But required for app exchange listing app for security fetures.
also please select post which have answer as a best solution which is below the post marked a best solution currently.
Samadhan Sakhale 3Samadhan Sakhale 3
ok thanks a lot 

Sam