You need to sign in to do that
Don't have an account?
himanshu huske 7
Please provide test class for Trigger
I Have Object : Country__c With Fields: Name__c,Capital_City__c,Region__c,Sub_Region__c,
Regional_Block__c
Country__c object has records of various countries
And in Lead Object I have Fields Country_1__c,Region__c,Capital_City__c,Sub_Region__c,Regional_Block__c
Whenever we insert/update any country name in lead Country_1__c field which exist in Country__c(object) record field Name__c
then populate all lead fields
Regional_Block__c
Country__c object has records of various countries
And in Lead Object I have Fields Country_1__c,Region__c,Capital_City__c,Sub_Region__c,Regional_Block__c
Whenever we insert/update any country name in lead Country_1__c field which exist in Country__c(object) record field Name__c
then populate all lead fields
trigger countryInfoUpdate on Lead (before insert, before update) { //List<Lead> lList = new List<Lead>(); Set<String> strSet = new Set<String>(); for(Lead l : trigger.new){ strSet.add(l.Country_1__c); } List<Country__c> conList = [Select id,Name__c,Capital_City__c,Region__c,Sub_Region__c, Regional_Block__c from Country__c Where Name__c in: strSet]; map<String,Country__c> conMap = new map<String,Country__c>(); for(Country__c c : conlist){ conMap.put(c.Name__c, c); } for(Lead l : trigger.new){ if(conMap.containsKey(l.Country_1__c)){ l.Region__c = conmap.get(l.Country_1__c).Region__c; l.Capital_City__c = conmap.get(l.Country_1__c).Capital_City__c; l.Sub_Region__c = conmap.get(l.Country_1__c).Sub_Region__c; l.Regional_Block__c = conmap.get(l.Country_1__c).Regional_Block__c; } } }
Try this test class
Please refer below links which might help you further
http://www.sfdcpoint.com/salesforce/test-class-with-example-salesforce/
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
You will understand test class in detail at test class in salesforce (https://sfdcwisdom.com/test-class-in-salesforce/)
For you query try this:
@istest
public class CountryInfoUpdateTest {
@istest
public static void testlead(){
Test.startTest();
country__c coun = new country__c();
coun .name__c = 'DemoName';
coun .Capital_City__c = 'capital';
coun .Region__c = 'sampleRegion';
insert c;
lead l = new lead();
l.lastname = 'test';
l.Company = 'xyz';
l.status = 'open - not contacted';
l.Country_1__c = 'DemoName';
insert l;
test.stopTest();
}
}