You need to sign in to do that
Don't have an account?
Rahul
hi friends, can anyone help me with test class of this code
trigger AssignToFirstOwnerForDuplicteLeads on Lead (before insert, before update) {
set <string> newEmaiSet = new set<string>();
set<string> newPhNumSet = new set<string>();
for(lead l1: trigger.new) {
if(l1.Email != null) {
newEmaiSet.add(l1.Email);
}
if(l1.phone != null) {
newPhNumSet.add(l1.phone);
}
}
List<lead> leadWithMatchingEmail = [select id, email, OwnerId from lead where email in :newEmaiSet];
List<lead> leadWithMatchingPhone = [select id, phone, OwnerId from lead where email in :newPhNumSet];
Map<string, id> emailVSId = new Map<string, id>();
Map<string, id> phoneVSId = new Map<string, id>();
for(lead l1: leadWithMatchingEmail) {
emailVSId.put(l1.Email, l1.OwnerId);
}
for(lead l1: leadWithMatchingPhone) {
phoneVSId.put(l1.phone, l1.OwnerId);
}
for(lead l1: trigger.new) {
if(emailVSId.containsKey(l1.Email)) {
l1.OwnerId = emailVSId.get((l1.Email));
}
// if(phoneVSId.containsKey(l1.phone)) {
// l1.OwnerId = phoneVSId.get((l1.phone));
// }
system.debug('l1::@@'+l1);
}
}
Thanks in advance
set <string> newEmaiSet = new set<string>();
set<string> newPhNumSet = new set<string>();
for(lead l1: trigger.new) {
if(l1.Email != null) {
newEmaiSet.add(l1.Email);
}
if(l1.phone != null) {
newPhNumSet.add(l1.phone);
}
}
List<lead> leadWithMatchingEmail = [select id, email, OwnerId from lead where email in :newEmaiSet];
List<lead> leadWithMatchingPhone = [select id, phone, OwnerId from lead where email in :newPhNumSet];
Map<string, id> emailVSId = new Map<string, id>();
Map<string, id> phoneVSId = new Map<string, id>();
for(lead l1: leadWithMatchingEmail) {
emailVSId.put(l1.Email, l1.OwnerId);
}
for(lead l1: leadWithMatchingPhone) {
phoneVSId.put(l1.phone, l1.OwnerId);
}
for(lead l1: trigger.new) {
if(emailVSId.containsKey(l1.Email)) {
l1.OwnerId = emailVSId.get((l1.Email));
}
// if(phoneVSId.containsKey(l1.phone)) {
// l1.OwnerId = phoneVSId.get((l1.phone));
// }
system.debug('l1::@@'+l1);
}
}
Thanks in advance
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.
Let us know if this will help you
All Answers
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.
Let us know if this will help you