-
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
What Role Does Salesforce Play in High-Tech Success?
The high-tech sector is experiencing explosive growth, emerging as a global economic powerhouse. Projections indicate that this industry's global market value will rise to $16…
How to Freeze and Deactivate the User Account | Salesforce Developer Guide
Introduction Hello all, here we are going to learn about freezing the users accounts and deactivating the user account. Sometimes we need to delete some…
Salesforce.org Aids Nonprofits in Connecting Data on An Integrated Platform
Salesforce has announced new innovations in their Winter '22 release that would assist organizations and grantmakers in meeting these problems by allowing them to access technology…