You need to sign in to do that
Don't have an account?

i want to write test class for below trigger plz help me
trigger Lead_Update on Lead (before insert,before update) {
String dam ='';
String jub='';
String west1 ='';
String west2 = '';
String central = '';
String Gcc = '';
String uid=UserInfo.getUserId();
User UserDetails = [select User.Lead_Region__c, User.Location__c from User Where User.Id =:uid limit 1];
string UserLoc = UserDetails.Location__c;
string LeadRegion = UserDetails.Lead_Region__c;
for(Lead lt : trigger.new){
lt.Lead_City__c = UserLoc;
lt.Region__c = LeadRegion;
}
}
String dam ='';
String jub='';
String west1 ='';
String west2 = '';
String central = '';
String Gcc = '';
String uid=UserInfo.getUserId();
User UserDetails = [select User.Lead_Region__c, User.Location__c from User Where User.Id =:uid limit 1];
string UserLoc = UserDetails.Location__c;
string LeadRegion = UserDetails.Lead_Region__c;
for(Lead lt : trigger.new){
lt.Lead_City__c = UserLoc;
lt.Region__c = LeadRegion;
}
}
1) https://trailhead.salesforce.com/modules/apex_testing
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
You write a test class for this the same way that you would any other:
- Set up some data for the Trigger to access
- Verify the behaviour with asserts.
Try below code
Let us know if this will help you