-
Test is not going inside "trigger.new" while testing Salesforce Trigger
In my trigger testing, the test is not going inside trigger.new
`
trigger Setpricebookentry1 on Product2 (after insert)
{
SetprodIdSet = Trigger.newMap.keySet();
listlistpbe=new list ();
Pricebook2 prbook=[select id from Pricebook2 where isStandard=true and isActive=true];
system.debug('++++++>'+prbook);
for(Product2 po:Trigger.New)
{
system.debug('=====>'+trigger.new);
Pricebookentry pbe=new Pricebookentry();
pbe.UnitPrice=10;
pbe.Pricebook2Id=prbook.id;
pbe.Product2Id=po.id;
listpbe.add(pbe);
}
if(listpbe.size()>0)
{
insert listpbe;
system.debug('------>'+listpbe);
}
}
`this is my test code
`
@istest
public class TestSetpricebookentry1
{
@istest
public static void mytest()
{
Product2 po=new Product2();
po.Name='Raghav';
po.IsActive=true;
insert po;
Id pricebookId = Test.getStandardPricebookId();
PricebookEntry standardPrice = new PricebookEntry();
standardPrice.Pricebook2Id = pricebookId;
standardPrice.Product2Id =po.Id;
standardPrice.UnitPrice = 10000;
standardPrice.IsActive = true;
insert standardPrice;
}
}
`
Log In to reply.
Popular Salesforce Blogs

Salesforce Customer Portal: Features, Industry Use Case, and Benefits
The ideal features in a customer portal may vary depending on the industry, business needs, and the types of customers that the portal is meant…

How Our Favorite Sites and Tools Use Machine Learning | Salesforce Guide
As companies collect more and more data about their customers, an increased amount of duplicate information starts appearing in the data as well, causing a…

How to Pass Data From One Component to Another in Salesforce Lightning?
We have to build a lot of components for building up a Salesforce Lightning Application. Lightning events are the right way to pass the values…