-
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
![](https://images.forcetalks.com/wp-content/uploads/2022/01/27123646/sa_1643286925E2ca%20banner.jpg)
Simplifying Case Management in Salesforce Service Cloud
Research shows that 68% of consumers are willing to pay more if they know they will receive superior customer service. In fact, customer service is…
![](https://images.forcetalks.com/wp-content/uploads/2023/08/18043057/Blog-banner-Sep-2022-2023-08-18T100042.959.png)
Interview Question Part – 3
1. What is an Apex class in Salesforce? An Apex class in Salesforce is a blueprint or template for creating custom business logic and functionality.…
![salesforce too expensive](https://images.forcetalks.com/wp-content/uploads/2020/05/27154229/salesforce-too-expensive.png)
Is Salesforce Too Expensive? 5 Ways To Control The Benefit-cost Ratio
When I discuss Salesforce with others, I'm often confronted with an argument that Salesforce is far too expensive and can be substituted with much cheaper…