You need to sign in to do that
Don't have an account?
help me with the test class for my trigger
trigger createopp on Call_Abandon_List__c (after insert,after update)
{
List<opportunity> opps=new List<opportunity>();
for(Call_Abandon_List__c ca:Trigger.New)
{
/* if(Trigger.IsInsert && ca.Status__c=='converted')
{
opportunity O=new Opportunity();
O.Name='ca.Name';
O.Product_Id__c=ca.Product__c;
opps.add(O);
}
*/
// after update
if(Trigger.IsUpdate && ca.Status__c!=Trigger.oldMap.get(ca.Id).Status__c && ca.Status__c=='converted'&&ca.Converted_to_Opportunity__c==false)
{
opportunity o=new Opportunity();
O.Name=ca.Name;
o.Accountid = ca.Account__c;
o.Product_Id__c=ca.Product__c;
o.StageName = 'New';
o.Probability = 10;
o.CloseDate= Date.Today();
o.LeadSource = 'Abandon List';
o.Secondary_User__c = ca.Ownerid;
QueueSobject que = [Select Id, Queue.Id From QueueSobject Where Queue.DeveloperName='calllist_queue' Limit 1];
o.Ownerid = que.Queue.Id;
o.Converted_to_Opportunity__c=true;
opps.add(o);
system.debug('opportunity is '+o);
}
}
if(!opps.IsEmpty())
{
system.debug('********entered if');
try
{
insert opps;
}
catch(Exception e)
{
system.debug('******exception thrown'+e);
}
}
}
Hi K_dev,
For the code coverage of your trigger you need to insert some records of Call_Abandon_List__c and also to update some records for the same object from your test class. As after insert/update your trigger get called that will automatically cover your trigger code coverage.
Use following code and modify it according to your need in your test class it will help you to cover your trigger code coverage.
Account aa = new Account(name = 'Test account') ;
insert aa ;
Call_Abandon_List__c cc = new Call_Abandon_List__c (name = 'Test name' , Account__c = aa.Id);
insert cc ;
cc.name = 'Updated name' ;
update cc ;
For more details on test classes visit http://forcespider.wordpress.com/
If this post helps you then hit kudus by clicking on star and accept my post as a solution to your question.