Activity Forums Salesforce® Discussions Adding Products to Opportunity Line items in salesforce?

  • Suraj

    Member
    April 13, 2017 at 9:59 am

    Hi Manpreet,

    Try this,

    public class ProductEntry {
    public static void CustomProductadd(){
    Product2 pro=new Product2(name ='ProductName',IsActive=true);
    insert pro;
    PriceBook2 customprice=new PriceBook2(name='CustomPriceBook',IsActive=true);
    insert customprice;
    PriceBook2 standardPb=[select id from Pricebook2 where isStandard=true];
    PriceBookEntry pbeStandard=new PriceBookEntry(Product2Id=pro.Id,PriceBook2Id=standardPb.Id,isActive=true,UnitPrice=1);
    insert pbeStandard;
    PricebookEntry pbe=new PriceBookEntry(Product2Id=pro.Id,PriceBook2Id=customprice.Id,isActive=true,UnitPrice=1);
    insert pbe;
    OpportunityLineItem lineitem=new OpportunityLineItem(OpportunityId='OPPID',PriceBookEntryId=pbe.Id,Quantity=1,Unitprice=1);
    insert lineitem;
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos