You need to sign in to do that
Don't have an account?
MAITREYEE DINGARE
0% test coverage for trigger to insert record
Hello All,
I am new to development. I have written a trigger to add a newly created product into the standard price book. But while deployment to PROD, it is failing because of 0% code coverage.
Could you please help me here?
Following is my trigger:
I am new to development. I have written a trigger to add a newly created product into the standard price book. But while deployment to PROD, it is failing because of 0% code coverage.
Could you please help me here?
Following is my trigger:
trigger createPriceBookEntry on Product2 (after insert) { List<priceBookEntry> priceBookEntryList= new List<priceBookEntry>(); String pricebkId= [SELECT id from Pricebook2 where isStandard=true][0].Id; for(Product2 prod: trigger.new){ priceBookEntry priceBkEntry= new priceBookEntry(); priceBkEntry.Product2Id= prod.Id; priceBkEntry.Pricebook2Id= pricebkId; priceBkEntry.IsActive= True; priceBkEntry.UnitPrice= 0; // Dummy Value priceBkEntry.UseStandardPrice= False; priceBkEntry.External_ID__c = prod.MSOFT_Artikelnummer__c; //Add more fields as per requirement priceBookEntryList.add(priceBkEntry); } if(priceBookEntryList.size()>0) { insert priceBookEntryList; } }Following is the test class:
@isTest public class TestQuoteLineItem { Static testmethod void insertRecord() { priceBookEntry priceBkEntry= new priceBookEntry(); priceBkEntry.Pricebook2Id= '01s09000003qN9eAAE'; priceBkEntry.IsActive= True; priceBkEntry.UnitPrice= 0; // Dummy Value priceBkEntry.UseStandardPrice= False; priceBkEntry.External_ID__c = 'test'; priceBkEntry.Product2Id = '01t1l000005CY2aAAG'; //Add more fields as per requirement insert priceBkEntry; //system.assertequals(priceBkEntry.Pricebook2Id,priceBkEntry.Pricebook2Id); //System.debug('My debug message: ' + priceBkEntry.Product2Id); } }Thank you so much for your help in advance!
try following test class with 100% code coverage.
let me know if it helps you and don't forget to marking it as best so that it can help to others in future.
Thank you
All Answers
Greetings!
Test Class
Please mark it as the best answer if it helps you to fix the issue.
Thank you!
Regards,
Malika Pathak
try following test class with 100% code coverage.
let me know if it helps you and don't forget to marking it as best so that it can help to others in future.
Thank you
Thank you for your help. Veer's solution helped me. Now I have 100% test coverage.
Have a nice day.
Thank you!