You need to sign in to do that
Don't have an account?
anandanand
Test class for trigger
How to write test class for trigger
am new to apex
trigger check on Order__c (after insert) {
Order__c to=trigger.new[0];
Opportunity q=[select id from Opportunity where id=:to.Opportunity__c];
list<OpportunityLineItem> ql=[select id,ListPrice,PriceBookEntry.Name,PriceBookEntry.Product2Id ,Subtotal,TotalPrice from OpportunityLineItem where OpportunityId=:q.id];
for(OpportunityLineItem qli:ql){
Accomodation__c lm=new Accomodation__c();
lm.Price__c=qli.ListPrice;
lm.Name=qli.PriceBookEntry.Name;
lm.Order__c=to.id;
insert lm;
}
}
Hi,
Before helping you in the test coverage, I wanted to ask you whether your trigger is bulk enabled?
If Yes, are you aware of the "Apex Governor Limits".
Just a small tip, never insert any dml statement in a for loop
Take a List of Type Accomodation and add the object there and outside the for loop insert the list.
for example:
And here are the guidelines for your test coverage.
Create a class with the Template as "Test Class".
This should give you atleast the minimum code coverage for your trigger.
All Answers
Hi,
Before helping you in the test coverage, I wanted to ask you whether your trigger is bulk enabled?
If Yes, are you aware of the "Apex Governor Limits".
Just a small tip, never insert any dml statement in a for loop
Take a List of Type Accomodation and add the object there and outside the for loop insert the list.
for example:
And here are the guidelines for your test coverage.
Create a class with the Template as "Test Class".
This should give you atleast the minimum code coverage for your trigger.
Thank u very much rmeh
it works fine