You need to sign in to do that
Don't have an account?
sudhIr Narayan
Code Coverage
Hi
I wrote a trigger on appointment object which will update lead status in lead which is working fine. I wrote a test class for trigger as mentioned below it is still showing me same 0% please suggest me how to fix
I wrote a trigger on appointment object which will update lead status in lead which is working fine. I wrote a test class for trigger as mentioned below it is still showing me same 0% please suggest me how to fix
Trigger ====== trigger Update_Lead_Status on Appointment_Detail__c (After Insert, After Update) { set<id> ADId = new set<id>(); for(Appointment_Detail__c AD : trigger.new) { ADId.add(AD.ID); Appointment_Detail__c ApptDt = [ SELECT Completed__c,Lead_Id__c FROM Appointment_Detail__c where id in :ADId ]; If ( ApptDt.Lead_Id__c <> null && ApptDt.Completed__c == 'Yes' ) { Lead ld = [select staTus from Lead where id = :ApptDt.Lead_Id__c]; ld.status = 'SQL'; update ld; } } } Test Class ========== @isTest(SeeAllData = true) private class test_appointment_leadstatus { public static testmethod void testlead() { test.startTest(); Appointment_Detail__c ApptDt = [ SELECT Completed__c,Lead_Id__c FROM Appointment_Detail__c where id = 'a1gm000000001GJ']; If ( ApptDt.Lead_Id__c <> null && ApptDt.Completed__c == 'Yes' ) { Lead ld = [select status from Lead where id = :ApptDt.Lead_Id__c]; ld.status = 'SQL'; update ld; } test.stopTest(); } }
Thanks
Sudhir
You then won't need the @SeeAllData=true, as your unit test data will be created by the test itself.
I'm also duty bound to point out that you have SOQL queries nested inside for loops in your trigger, so this probably wouldn't handle mass insert/updates (from the data loader, for example) without breaching governor limits. You can find out more about this at :
https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code
All Answers
You then won't need the @SeeAllData=true, as your unit test data will be created by the test itself.
I'm also duty bound to point out that you have SOQL queries nested inside for loops in your trigger, so this probably wouldn't handle mass insert/updates (from the data loader, for example) without breaching governor limits. You can find out more about this at :
https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code
You have not the trigger properly for Bulk data.
This will give you Too many Soql, if you insert more than 100 records at once.
Try the below link for Trigger Best Practices.
https://developer.salesforce.com/page/Apex_Code_Best_Practices
If you want to Test coverege for this Trigger,
you should insert a lead and Appointment_Detail__ records.