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

code coverage for opportunity trigger
Hi,
I wrote a trigger on opportunity trigger which will update the custom object which is working fine
Thanks
Sudhir
I wrote a trigger on opportunity trigger which will update the custom object which is working fine
trigger Insert_Order_checklist on Opportunity (After Insert, After Update) { /* This trigger is used to insert into order checklist when opportunity stage name = 1 - closed won */ list<Opportunity> OP = [select id,name from opportunity where id = :Trigger.newMap.keySet() and StageName = '1 - Closed Won' limit 1]; List<Order_Processing_Checklist__c> OPCi = new list<Order_Processing_Checklist__c>(); // Integer CL = [select count() from opportunity where id = :Trigger.newMap.keySet() and StageName = '1 - Closed Won']; if ( [select count() from opportunity where id = :Trigger.newMap.keySet() and StageName = '1 - Closed Won'] > 0 ) { if ( [select count() from Order_Processing_Checklist__c where Opportunity_Name__c = :Trigger.newMap.keySet() ] == 0 ) { for ( opportunity opp : op ) { //list<Order_Processing_Checklist__c> delOP = [select id from Order_Processing_Checklist__c where Opportunity_Name__c = :opp.id ]; //Delete delOp; Order_Processing_Checklist__c OPC = new Order_Processing_Checklist__c(); OPC.Opportunity_Name__c = opp.id; OPC.name = opp.name; OPCi.add(OPC); } Insert OPCi; } } }I also wrote a test class for above trigger it is not giving code coverage please suggest me what is the mistake in this test class
@isTest(SeeAllData = true) private class Test_Insert_Order_checklist { public static testmethod void testorderchecklist() { test.startTest(); list<Opportunity> OP = [select id,name from opportunity where StageName = '1 - Closed Won' limit 1]; List<Order_Processing_Checklist__c> OPCi = new list<Order_Processing_Checklist__c>(); for ( opportunity opp : op ) { Order_Processing_Checklist__c OPC = new Order_Processing_Checklist__c(); OPC.Opportunity_Name__c = opp.id; OPC.name = opp.name; OPCi.add(OPC); } Insert OPCi; test.stopTest(); } }
Thanks
Sudhir
All Answers
Thanks
Sudhir