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

Help me with the test class for my trigger
trigger create_oli on Opportunity (after insert)
{
list<OpportunityLineItem> lst_oli=new list<OpportunityLineItem >();
map<string,string> pdcts=new map<string,string>();
for(Opportunity o:Trigger.New)
{
if(o.Product_Id__c!=null)
{
pdcts.put(o.Id,o.Product_Id__c);
}
}
if(!pdcts.IsEmpty())
{
map<String,string> pbe_map=new map<string,string>();
list<pricebookentry> pbe=[select id, Product2Id from PricebookEntry where Product2Id IN:pdcts.values()];
for(pricebookentry p:pbe)
{
pbe_map.put(p.Product2Id,p.Id);
}
for(string s:pdcts.Keyset())
{
if(pbe_map.containsKey(pdcts.get(s)))
{
OpportunityLineItem oli=new OpportunityLineItem();
oli.Opportunityid=s;
//oli.Product2=o.Product_Id__c;
oli.Quantity = 1;
oli.PricebookEntryId=pbe_map.get(pdcts.get(s));
oli.TotalPrice=1000;
lst_oli.add(oli);
}
}
if(!lst_oli.IsEmpty())
{
insert lst_oli;
}
}
}