• #19058
    Salesforce | Manpreet Manpreet #229

    Adding Products to Opportunity Line items in salesforce?

    I need to Add Products to Opportunity Line items.How can i achieve it?


    Salesforce | Suraj Suraj #168

    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;

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?