• KOUSHIK SARKAR
  • NEWBIE
  • -2 Points
  • Member since 2020
  • ZERODAYINFOSEC
  • ZERODAYINFOSEC

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
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:
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!
can anyone give me apex trigger examples for better understanding of the apex trigger 
  • February 23, 2020
  • Like
  • 1
Hi,

I have a number field (Number, 0) but when i put valuee 10000 in it it will diplay it as 10,000 i want to display it without comma.
I have selected number field because i need to select Max number from it and add 1 in Max number for new entry.
Can any body help me how i can do it.

Thanks,
Faraz

I am working in enterprise edition. As winter 14 changed... i am unable to see the option reset security token . In devoloper edition it is visible. So from Enterprise edition i am unable to find.

  • December 16, 2013
  • Like
  • 2