You need to sign in to do that
Don't have an account?
suneel rao
How to write test class for the after insert trigger
Hi everyone,
Can anyone hlep me how to write the test class for the after insert trigger. I'm new to salesforce.
My trigger is as below
trigger ChangeLeadStatus on Task (after update) {
Set<Id> leadIds = new Set<Id>();
for(Task tsk : trigger.new){
if(tsk.Status == 'Completed' && String.valueOf(tsk.whoId).startsWith('00Q')){
leadIds.add(tsk.whoId);
}
}
Map<Id,Lead> allRealtedLeads = new Map<Id,Lead>([Select status from Lead where ID IN :leadIds]);
List<Lead> leadsToUpdate = new List<Lead>();
for(Task tsk : trigger.new){
if(tsk.Status == 'Completed' && String.valueOf(tsk.whoId).startsWith('00Q') && allRealtedLeads.containsKey(tsk.whoId)){
allRealtedLeads.get(tsk.whoId).Status = tsk.Subject;
leadsToUpdate.add(allRealtedLeads.get(tsk.whoId));
}
}
if(leadsToUpdate.size() > 0){
update leadsToUpdate;
}
}
regards,
Suneel.
Can anyone hlep me how to write the test class for the after insert trigger. I'm new to salesforce.
My trigger is as below
trigger ChangeLeadStatus on Task (after update) {
Set<Id> leadIds = new Set<Id>();
for(Task tsk : trigger.new){
if(tsk.Status == 'Completed' && String.valueOf(tsk.whoId).startsWith('00Q')){
leadIds.add(tsk.whoId);
}
}
Map<Id,Lead> allRealtedLeads = new Map<Id,Lead>([Select status from Lead where ID IN :leadIds]);
List<Lead> leadsToUpdate = new List<Lead>();
for(Task tsk : trigger.new){
if(tsk.Status == 'Completed' && String.valueOf(tsk.whoId).startsWith('00Q') && allRealtedLeads.containsKey(tsk.whoId)){
allRealtedLeads.get(tsk.whoId).Status = tsk.Subject;
leadsToUpdate.add(allRealtedLeads.get(tsk.whoId));
}
}
if(leadsToUpdate.size() > 0){
update leadsToUpdate;
}
}
regards,
Suneel.
Please try this code :
Please mark this question as Solved if your question was answered so that others can view it as a proper solution.
Thanks,
Apoorv
All Answers
Here is the test class for your trigger:
Please let me know how this works for you, mark this as Solved if this helps you so that others can view it as a proper solution.
Thanks,
Apoorv
Please try this code :
Please mark this question as Solved if your question was answered so that others can view it as a proper solution.
Thanks,
Apoorv
Glad to be of help.
Could you please mark this question as Solved then, it will help other users to view it as a proper solution.
Thanks,
Apoorv
trigger Verification on Inquiry_Form_Leads__c (after insert) {
list<string> Email = new list<string> ();
list<string> phone = new list<string> ();
list<Lead> test = new list<Lead> ();
list<Lead> test1 = new list<Lead> ();
list<Lead> test2 = new list<Lead> ();
for(Inquiry_Form_Leads__c IL :trigger.new){
if (IL.Email__C!= null){
Email.add(IL.Email__C);
}
if (IL.Cell_Phone_Number__c!= null){
phone.add(IL.Cell_Phone_Number__c);
}
}
test1=[SELECT id, Email, Phone, Status__c FROM Lead WHERE Email IN : Email ];
test=[select Phone,Email,Status__c from Lead where Id IN: test1];
system.debug('////'+test);
for(Lead t :test){
if(test.size()!=null){
t.Converted__c= true;
t.Status__c='Matched';
test2.add(t);
}
}
update test2;
}
Regards,
Suneel.